looping last column counter XL 97

lambuhere1

Registered User.
Local time
Today, 20:48
Joined
Nov 19, 2001
Messages
28
Hi Members

I have a peculiar problem. I don't know why VBA is behaving like this. I have data in different columns, imported from a text file and during importing I get blank columns. First I count the maximum number of columns and then use this variable to do the removal of blank columns in Do loop. After I remove my blank columns, I calculate the max columns in my worksheet. But this gives the same number of columns as the original b4 deletion. I don't know why this is happening? Can anyone guess. I want the latest max number of columns further in my code.

lastcolumn = Cells.SpecialCells(xlCellTypeLastCell).Column
MsgBox " Last Col is " & lastcolumn


i = lastcolumn
Do Until i < 1

If Cells(1, i).Value = "" Then
Cells(1, i).EntireColumn.Delete
i = i - 1
Else
i = i - 1
End If
Loop

lastcol = Cells.SpecialCells(xlCellTypeLastCell).Column
MsgBox " new col after blank deletion" & lastcol

'I am obtaining lastcol and lastcolumn as same number.

Thanks for your help.

Ram P
 

Users who are viewing this thread

Back
Top Bottom