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 post, you’ll learn how to Find Blank cells in excel so that you can remove or delete the blank cells form...
In this article, you’ll learn what is a Gauge Chart in Microsoft Excel. Also, you will learn how to add...
Microsoft Excel provides a shortcut for the users to move columns in excel using two different ways – using Shift...