VB Question on syntax

arkusM

Well-known Member
Joined
Apr 12, 2007
Messages
560
I have found a bit of code to track changes in a spreadsheet (at Ozgrid)

But I am puzzled as to this bit here
Code:
.Cells(.Rows.Count, x).End(xlUp)[COLOR=blue][B](2, 1)[/B][/COLOR]
I don't understand what th blue blodness is doing. Is it shorthand for an Offset?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Not quite - it is shorthand for Cells(2, 1)
 
Upvote 0
Not quite - it is shorthand for Cells(2, 1)
thanks Rory,

So the red bit provides a relative reverence to the blue bit?
Rich (BB code):
.Cells(.Rows.Count, x).End(xlUp)(2, 1)

Acting like an "offset"?
 
Last edited:
Upvote 0
Hi, It achieves the same result as setting a range as an Range Object as below.
Both bits of code produce the same Address.
Code:
Dim t, m, Rng As Range
Set Rng = Range("A4:C10")
m = Rng.Cells(2, 3).Address
'm = $C$5

 'or

t = Range("A4:C10")(2, 3).Address
't= $C$5
Regards Mick
 
Upvote 0
Hi, It achieves the same result as setting a range as an Range Object as below.
Both bits of code produce the same Address.
Code:
Dim t, m, Rng As Range
Set Rng = Range("A4:C10")
m = Rng.Cells(2, 3).Address
'm = $C$5
 
 'or
 
t = Range("A4:C10")(2, 3).Address
't= $C$5
Regards Mick


Oh Ok. Thanks. I think that make some sense. I will continute to experiment and wrap my mind around this. I think this would have saved my a bunch of typing in my coding attempts earlier!! HAHA
 
Upvote 0
thanks Rory,

So the red bit provides a relative reverence to the blue bit?


Acting like an "offset"?


Haha, that is a funny typo!! Not entirely inappropriate, but still funny!!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
 
Upvote 0
The slightly odd thing is that the Cells references are not constrained to the range to which you apply them, so you can use:
Code:
Range("A1").Cells(2,2)
to get to B2 for example. It's like an offset except 0 based rather than 1 based - i.e. Cells(1,1) is the equivalent of Offset(0,0)
 
Upvote 0
The slightly odd thing is that the Cells references are not constrained to the range to which you apply them, so you can use:
Code:
Range("A1").Cells(2,2)
to get to B2 for example. It's like an offset except 0 based rather than 1 based - i.e. Cells(1,1) is the equivalent of Offset(0,0)

Ok. That is cool. Thanks.
This is obviously not my code, but I am adapting it.
Is this syntax a good or bad practice? It seems to have some useful application, at least to my mind. But I don't want to use it if it is a "bad habit".
 
Upvote 0
I would personally specify the Cells property rather than just using the parentheses.
 
Upvote 0
I would personally specify the Cells property rather than just using the parentheses.


Cool. Thanks. I guess if the original code had done that I would not have asked my question in the first place. I asked a redendant question!!
Thank you for your patience and help!!

Cheer!

Mark
 
Upvote 0

Forum statistics

Threads
1,203,686
Messages
6,056,737
Members
444,888
Latest member
Babi_mn

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