Created
July 27, 2021 13:32
-
-
Save stevesohcot/10d0aa337c522ed31f5883ff0a28bd6d to your computer and use it in GitHub Desktop.
VBA how many rows in Excel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Public Function HowManyRows(sheetName As String) As Integer | |
| 'Find out how many row there are | |
| Dim i As Integer | |
| Sheets(sheetName).Select | |
| Range("A1").Select | |
| Do | |
| ActiveCell.Offset(1, 0).Select | |
| Loop Until ActiveCell.FormulaR1C1 = "" | |
| 'Move up one row so we know where the last row of data is | |
| ActiveCell.Offset(-1, 0).Select | |
| Dim totalRows As Integer | |
| totalRows = ActiveCell.Row ' do NOT subtract one for the header | |
| HowManyRows = totalRows | |
| End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment