Skip to content

Instantly share code, notes, and snippets.

@stevesohcot
Created July 27, 2021 13:32
Show Gist options
  • Select an option

  • Save stevesohcot/10d0aa337c522ed31f5883ff0a28bd6d to your computer and use it in GitHub Desktop.

Select an option

Save stevesohcot/10d0aa337c522ed31f5883ff0a28bd6d to your computer and use it in GitHub Desktop.
VBA how many rows in Excel
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