What is "Me.Range"?

dl7631

Board Regular
Joined
Mar 6, 2009
Messages
114
Dear gurus, probably a simple question:

What does "Me.Range" mean? More specifically, I don't understand the second line of this piece of VBA code:

Dim LP as Long
LP = Me.Range("r4").Value

Thank you!
 

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.
Me is usually an object variable that refers to a sheet..

Specifically, I'm guessing that snippet is from some Worksheet Event code, like

Private Sub Worksheet_Change(ByVal Target As Range)


In that case, Me refers to whatever sheet the code is in..

So if the code is in say Sheet1
then me is simply Sheets("Sheet1")

LP = Me.Range("r4").Value
LP = Sheets("Sheet1").Range("r4").Value

Make sense?
 
Upvote 0
"Me" is a reference to the object that contains the code. In this case a worksheet but can also be a userform or class.

That code is the equivalent of (assuming the sheet is called sheet 1)

Dim LP as Long
LP = Worksheets("Sheet1").Range("r4").Value
 
Upvote 0
Most often, you'll use the Me keyword in sheet modules or sheet code, or in button code, or userform code.

In other words, it's not for code in standard modules....

If this makes no sense, check here for info on code placement:
http://www.mcgimpsey.com/excel/modules.html
 
Upvote 0

Forum statistics

Threads
1,224,755
Messages
6,180,758
Members
452,996
Latest member
nelsonsix66

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