VBA Immediate window

jakobt

Active Member
Joined
May 31, 2010
Messages
337
Have written a macro to identify the last used row in a column:

sub_find_last_row()

dim last_row as integer
lastrow = range("B2"), range("B" & rows.count).end(xlup).row
end sub

I want to test if a row number was assigned to the variable so I open immediate window:

? Last_row

But no number is shown/calculated.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Last_row is declared within that routine. After you have run it, the variable goes out of scope and loses its value. Really, I suspect that should be a function.
 
Upvote 0
change this line of code

Code:
[COLOR=#333333]lastrow = range("B2"), range("B" & rows.count).end(xlup).row

to

[/COLOR]
Code:
[COLOR=#333333]last_row = range("B2"), range("B" & rows.count).end(xlup).row[/COLOR]

You have not been consistent in your variable name.
 
Upvote 0
There are a number of problems with the code you supplied, try
Code:
Sub find_last_row()

Dim last_row As Integer
last_row = Range("B" & Rows.Count).End(xlUp).Row
Debug.Print last_row
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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