Immediate Window

Darchcruise

New Member
Joined
Jun 3, 2011
Messages
8
Hi,

Whenever I run the code below in the module the msgbox returns a value, i.e 9 (signifying 9th row).

Sub test()
x = ActiveCell.Row
MsgBox x
End Sub


But whenever I use the immediate window (print x) or the watch window (x) nothing happens . In other words, it doesn't tell me a value (doesn't tell me what row I'm on). Can someone please explain? How can I make it work?

Thanks,
Jason
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
The variable X only exists within the procedure you are using it in (good practice would have you Dim it inside there as well), so you cannot refer to X from outside the routine unless you have executed a breakpoint within your procedure (doing that would mean the procedure is still active). What you would do in the Immediate Window is simply...

MsgBox ActiveCell.Row
 
Upvote 0
If required the result can be saved in public variable:
Rich (BB code):

' Put code in Module1
Public X

Sub Save_X_value()
  ' All local variables lives only while runtime
  ' But you can store result in public variable
  X = ActiveCell.Row
  Show_X_value
  ' After that press Ctrl-G to go in Immediate window
  ' type: ?X
  ' and press Enter to see X value
End Sub

Sub Show_X_value()
  MsgBox "TypeName(X)=" & TypeName(X) & vbLf & "X=" & X
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,749
Members
452,940
Latest member
rootytrip

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