How do I find the number of used columns in an Excel sheet using VBA?
Dim lastRow As Long
lastRow = Sheet1.Range(\"A\" & Rows.Count).End(xlUp).Row
MsgBox
It's possible you forgot a sheet1 each time somewhere before the columns.count, or it will count the activesheet columns and not the sheet1's.
Also, shouldn't it be xltoleft instead of xltoright? (Ok it is very late here, but I think I know my right from left) I checked it, you must write xltoleft.
lastColumn = Sheet1.Cells(1, sheet1.Columns.Count).End(xlToleft).Column