Get row count of last row in sheet using VBA

mohitkumar966

New Member
Joined
May 29, 2018
Messages
6
Hi All,

I am trying to get the last row count in excel using vba using the below code:

lastrow = Cells(Rows.Count, "A").End(xlUp).Row

but it is not giving me the required result. I am getting 1 as output. even though I checked manually that data is there and Ctrl+Shift+End is also taking me to the last cell of the data.

Thanks in advance.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Works for me. Did you dimension "lastrow" correctly?

This is my code:

Code:
Dim lastrow As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
MsgBox lastrow

and I get the correct message...last used row in column A.

I don't think the dimensioning would matter, but maybe.
 
Upvote 0
Hi All,

I am trying to get the last row count in excel using vba using the below code:

lastrow = Cells(Rows.Count, "A").End(xlUp).Row

but it is not giving me the required result. I am getting 1 as output. even though I checked manually that data is there and Ctrl+Shift+End is also taking me to the last cell of the data.
Do you have data in Column A or does your data start in a different column?
 
Upvote 0
Thanks guys for help. Got the solution. I was actually in different window and hence was not getting the correct answer.
Used window function to switch window and then it is working fine.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top