VBA, Excel Get Number of Columns and Rows With Data, Get_Count() (Sample Code and Download)
In this article I will explain the function Get_Count(). Get_Count() is a function which I have written myself. The main purpose of this function is to return the number of rows or columns of data starting from a specific cell. It is very useful when working with data that can dynamically increase or decrease. You can download the files related to this article here. The function code can be seen below:
intRow: The index of the first row with data in it.
intColumn: The index of the first column with data in it.
wrkSheet: The sheet which contains the data.
flagCountRows: A boolean value which determines whether to search for the number of columns or rows.
Output: The number of rows or columns of data.
Assume that we have the following data in our sheet. We are looking for the number of rows with data in it. In other words we are looking for the index of the first empty cell:
It can be seen that the data starts from row 2 column 1. Assume that these numbers are written in sheet1. Since we are looking for the number of rows, the flagCountRows parameter is set to true:
In this example we are looking for the number of columns in the data below, in sheet2:
You can download the files related to this article here.