Archive of Mr Excel Message Board


Back to Excel VBA archive index
Back to archive home



I can find the Last Row -- How about the last column??

Posted by bill.roberts on March 03, 2000 1:26 PM
Finding the last looks like this:

....FinalRow = Range("A65536").End(xlUp).Row

Finding the last column SHOULD like like this:

....FinalColumn = Range("IV1").End(xlLeft).Column

But it's not the answer...


Check out our Excel VBA Resources

Re: I can find the Last Row -- How about the last column??

Posted by Celia on March 03, 2000 4:15 PM

Bill

Should be :- End(xlToLeft)

You could have got this by using the macro recorder.

Celia

PS. Does your code work exactly as you've typed it (with "row" and "column" at the end)? This doesn't look right to me.


Re: I can find the Last Row -- How about the last column??

Posted by Jeff Mathewson on March 06, 2000 7:39 AM
Try this:


FinalRow = Range("A65536").End(xlUp).Row
do While cells(FinalRow,1) = ""
FinalRow = FinalRow - 1
Loop
FinalColumn = Range("IV1").End(xlToLeft).Column
Do While Cells(1,FinalColumn) <> ""
FinalColumn = FinalColum - 1
Loop
End Sub

Jeff.


Re: I can find the Last Row -- How about the last column??

Posted by Jeff Mathewson on March 10, 2000 6:12 AM
Celia,

Yes your right and I found that I did make an error when I posted the message. I forgot to add Trim to the statement. In the past, I found that "FinalRow = Range("A65536").End(xlUp).Row" always didn't work due to cells that looked emty but were not due to unseen spaces in the cell.

FinalRow = Range("A65536").End(xlUp).Row
do While trim(cells(FinalRow,1)) = ""
FinalRow = FinalRow - 1
Loop
FinalColumn = Range("IV1").End(xlToLeft).Column
Do While trim(Cells(1,FinalColumn)) <> ""
FinalColumn = FinalColum - 1
Loop
End Sub

Jeff.




This archive is from the original message board at www.MrExcel.com.
All contents © 1998-2004 MrExcel.com.
Visit our online store to buy searchable CD's with thousands of VBA and Excel answers.
Microsoft Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.