Finding the Last Row Number in VBA

Going from top to bottom

Dim lastRow As Integer
lastRow = Range("A4").End(xlDown).Row

Going from bottom to top

Dim lastRow As Integer
lastRow = Range("A" & Rows.Count).End(xlUp).Row

Current Region

Dim lastRowOfRegion As Integer
Dim firstRow As Integer
Dim lastRow As Integer
lastRowOfRegion = Range("A4").CurrentRegion.Rows.Count
lastRow = firstRow + lastRowOfRegion - 1

Used Range

Dim lastRowOfUsedRange As Integer
Dim firstRow As Integer
Dim lastRow As Integer
lastRowOfUsedRange = Application.ActiveSheet.UsedRange.Rows.Count
lastRow = firstRow + lastRowOfRegion - 1

Specialcells

Dim lastRow As Integer
lastRow = Cells.SpecialCells(xlCellTypeLastcell).Row

--

--

--

https://www.ozan.pl/aboutme/

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Extract subdirectory from git repository without losing history

OOPs Concepts in Java

Start of a new HNG Internship

Apache Airflow Series - 2

HTTPS SSL: Migration Guide

Use GDB to Debug Running Python Processes

Single resource having different data format and data type in RAML

The Most Beautiful Code I Ever Wrote

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ozan Tellioğlu

Ozan Tellioğlu

https://www.ozan.pl/aboutme/

More from Medium

Power BI Calculated Column vs Measure. Which one is more important?

Power BI: What is it? | HData Systems

Power BI: What is it? HData Systems

5 essential Excel Functionalities used by Data Analysts

Sales data set img

You don’t need VBA to create Excel reports in 2022. Use Microsoft PowerBI Report Builder instead.