How to Count the Rows & Columns in Selection using Excel VBA?

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
How to Count the Rows & Columns in Selection using Excel VBA?

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this article, you will learn about the SKEW.P function, the formula syntax and usage of the function in Microsoft...
In this article, you will learn about the SKEW function, the formula syntax and usage of the function in Microsoft...
In this article, you will learn about the RANK.EQ function, the formula syntax and usage of the function in Microsoft...
  • Excel
  • November 23, 2021