There are times when you might want to find out the total number of rows or columns that were selected in your Excel spreadsheet using Excel VBA.
How to Count the Rows in Selection using Excel VBA?
The easiest way to do this is to use the Selection.Rows and Selection.Columns object and use the Count property to get the count.
How to Count Rows in Selection using Excel VBA?
When you wanted to get the total rows that have been selected, you can use Selection.Rows as shown below.
Public Sub GetSelectedRows() MsgBox Selection.Rows.Count End Sub
How to Count Columns in Selection using Excel VBA?
If you need to count the number of columns that are selected, you can use Selection.Columns.Count as shown below.
Public Sub GetSelectedColumns() MsgBox Selection.Columns.Count End Sub