Try something like this:
Sub test()
Dim lastcol as integer
lastcol = Cells(1, Columns.Count).End(xlToLeft).Column
some other code
This will get you the last column.