Range values

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,834
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Assume I have the value of 1 in cell A1, 2 in B1, 3 in C1, 4 in A2, 5 in B2 and 6 in C2.

This is my code:

Code:
Dim Rng As Range


Set Rng = Range("A1:C1")

If I type:

Code:
Debug.Print Rng(1)

I get a value of 3, as expected.


However, why is it when I type:


Code:
Debug.Print Rng(4)


I get a value of 4.


I expected it to error because Rng is set to be the range A1 to C1 only.


Thanks
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Rng(4) is the same as Rng.Item(1,4) - See link below

Basically, it operates in the same way as Offset, so it can reference cells outside of the range.

https://docs.microsoft.com/en-us/office/vba/api/excel.range.item
 
Upvote 0
I think Rng(4) is not the same as Rng.Item(1,4), it's the same as Rng.Item(4).
rng(3) is C1 then it will go down to A2, so rng(4) is A2 not D1.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,540
Messages
6,125,409
Members
449,223
Latest member
Narrian

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