For a Limited Period!
Buy 2 ~ Free 1 pax OR Get 30% off for every pax on our scheduled classesAnalyzing Data with Power BI Microsoft Excel - Power Query (M365, 2021-2010) Microsoft Excel - Power Pivot (M365, 2021-2010) Please This email address is being protected from spambots. You need JavaScript enabled to view it. for more info. |
![]() |
VBA - Counting Rows & Columns & Sheets* 27/10/2001
When you have selected a range, it is sometimes useful to know how many rows or columns you have selected as this information can be used in your macros (for eg when you have reached the end, you will know it is time to stop the macros. This macro will do the trick.
Sub Count()
myCount = Selection.Rows.Count 'Change Rows to Columns to count columns
MsgBox myCount
End Sub
The next macro counts the number of sheets instead.
Sub Count2()
myCount = Application.Sheets.Count
MsgBox myCount
End Sub