1. How to find last row with value using vba in a specific column?
2. How to find last row with value using vba in a worksheet?
The questions above are entirely two different scenarios.
The first question will find the last row with value in a specific column within the worksheet.
While the second question find the last row with value of the entire worksheet.
The first question is applicable if you need to find the last row in different columns.
Let's say Column 1 or Column A, or Column 2 or Column B etc.
Example code below will find the last row in a specific column via VBA code.
===================
'command Cells(Rows.Count, 1) = find the last row with value in Column 1 for Sheet3
Dim last_row As Integer
last_row = Worksheets("sheet3").Cells(Rows.Count, 1).End(xlUp).Row
Msgbox last_row
'replace 1 with the desired column
'ex: command Cells(Rows.Count, 7) = find the last row with value in Column 7
===================
If you don't need to specify a worksheet or a specific sheet then just use ActiveSheet
===================
Dim last_row As Integer
last_row =Activesheet.Cells(Rows.Count, 1).End(xlUp).Row
Msgbox last_row
'replace 1 with the desired column number
===================
To find the last row that has been used in the whole worksheet, the VBA code below can do the task.
===================
Dim last_row As Integer
last_row = UsedRange.Rows.Count
Msgbox last_row
===================
VBA code above will count the last row even cells with white spaces or basically as the command implied it will count cells that has been used. So, cells with empty values or cells with a single or multiple spaces will be counted.
Excel Keyboard shortcuts guide
https://play.google.com/store/apps/details?id=chrisjoms.myexcelapplicationguide
Linux Android App cheat sheet:
2. How to find last row with value using vba in a worksheet?
The questions above are entirely two different scenarios.
The first question will find the last row with value in a specific column within the worksheet.
While the second question find the last row with value of the entire worksheet.
The first question is applicable if you need to find the last row in different columns.
Let's say Column 1 or Column A, or Column 2 or Column B etc.
Example code below will find the last row in a specific column via VBA code.
===================
'command Cells(Rows.Count, 1) = find the last row with value in Column 1 for Sheet3
Dim last_row As Integer
last_row = Worksheets("sheet3").Cells(Rows.Count, 1).End(xlUp).Row
Msgbox last_row
'replace 1 with the desired column
'ex: command Cells(Rows.Count, 7) = find the last row with value in Column 7
===================
If you don't need to specify a worksheet or a specific sheet then just use ActiveSheet
===================
Dim last_row As Integer
last_row =Activesheet.Cells(Rows.Count, 1).End(xlUp).Row
Msgbox last_row
'replace 1 with the desired column number
===================
To find the last row that has been used in the whole worksheet, the VBA code below can do the task.
===================
Dim last_row As Integer
last_row = UsedRange.Rows.Count
Msgbox last_row
===================
VBA code above will count the last row even cells with white spaces or basically as the command implied it will count cells that has been used. So, cells with empty values or cells with a single or multiple spaces will be counted.
Cheers..till next time!
================================
Free Android Apps:
Click on links below to find out more:
Excel Keyboard shortcuts guide
https://play.google.com/store/apps/details?id=chrisjoms.myexcelapplicationguide
Multiplication Table for early learners
Catholic Rosary Guide for Android:
Divine Mercy Chaplet Guide (A Powerful prayer):
Comments
Post a Comment