Excel VBA: Last Used Column
Solved
Eaheru
Posted messages
205
Status
Member
-
Darnc -
Darnc -
Hello,
I'm looking to find the last used column in an Excel sheet.
The equivalent of the command:
But for columns :)
Thank you in advance!
I'm looking to find the last used column in an Excel sheet.
The equivalent of the command:
lastc = Range("IV1").End(xlToLeft).Column But for columns :)
Thank you in advance!
8 answers
-
Hello,
following the same principle as what you mentioned, Range("IV1").End(xlToLeft).Column will return the last used column.
However, the concepts A65536 and IV1 are only compatible with Excel versions up to 2003. For later versions, the references would be A1048576 and XFD1.
So, here are the codes to retrieve the last row and the last column for all versions:
for the last row: derlig = Range("A" & Rows.Count).End(xlUp).Row for the last column dercol = Cells(1,Cells.Columns.Count).End(xlToLeft).Column
Thanks to pijaku and to his tip.
Best regards.
--
This guy wasn't very bright, as he was foolish.