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
Jean-François Corbett's answer is perfect. To be exhaustive I would just like to add that with some restrictons you could also use UsedRange.Columns.Count or UsedRange.Rows.Count.
The problem is that UsedRange is not always updated when deleting rows/columns (at least until you reopen the workbook).