Relative range selection

nbeene

New Member
Joined
Jul 8, 2002
Messages
5
Very simple question about VBA statement to select a relative range - in the old Excel language I would just write:

=select("r[1]c:r[15]c") - how do I do this in VBA

also, if I have name a cell and want to use the row of it in a reference I would have written it as:

=select("r[1]c:r"&row(!cellname)&"c[5]")

how do I accomplish this in VBA? I am sure it is a simplke thing I just cannot get the syntax right.

Thanks
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
On 2002-07-09 11:21, nbeene wrote:
Very simple question about VBA statement to select a relative range - in the old Excel language I would just write:

=select("r[1]c:r[15]c") - how do I do this in VBA

also, if I have name a cell and want to use the row of it in a reference I would have written it as:

=select("r[1]c:r"&row(!cellname)&"c[5]")

how do I accomplish this in VBA? I am sure it is a simplke thing I just cannot get the syntax right.

Thanks
If I understand your question, this is the syntax you're after:

ActiveCell.Range("A2:A16").Select
ActiveCell.Range("A2:E" & Range("cellname").Row).Select

Regards,
 
Upvote 0
That would give me the absolute reference I was looking for - but I do not think it would be the relative reference. What I am trying to do is if I am in an active cell, I want to select a range say five rows up in the same column to 2 rows up and three colums over - which would be

=select("r[-5]c:r[-2]c[3]")

the brackets imply that the reference is relative and not absolute - I just do not know how to do that in VBA
 
Upvote 0
On 2002-07-09 11:32, nbeene wrote:
That would give me the absolute reference I was looking for - but I do not think it would be the relative reference. What I am trying to do is if I am in an active cell, I want to select a range say five rows up in the same column to 2 rows up and three colums over - which would be

=select("r[-5]c:r[-2]c[3]")

the brackets imply that the reference is relative and not absolute - I just do not know how to do that in VBA

ActiveCell.Offset(-5, 0).Range("A1:C3").Select

This selects a range that is three rows by three columns with the starting point 5 rows above the active cell.

Regards,
 
Upvote 0
Thanks - that works fine - I am still getting used to the syntax

how about if you want to select everything between the active cell (which may vary, and cell C2), again, I would do it the old way as:

=select("rc:r2c3")

Thanks
 
Upvote 0
On 2002-07-09 12:48, nbeene wrote:
Thanks - that works fine - I am still getting used to the syntax

how about if you want to select everything between the active cell (which may vary, and cell C2), again, I would do it the old way as:

=select("rc:r2c3")

Thanks

Range("C2:" & ActiveCell.Address).Select

should do the trick for you.
 
Upvote 0
On 2002-07-09 13:04, Juan Pablo G. wrote:
On 2002-07-09 13:00, Barrie Davidson wrote:
Range("C2:" & ActiveCell.Address).Select

should do the trick for you.

Barrie, FYI, you can just use

Range("C2",ActiveCell).Select
Thanks Juan, I just learned something new.

I LOVE THIS BOARD !!!
:biggrin:
 
Upvote 0
Great - Thanks, since we are on a roll, what if I want to select column A in the active row? Old way =

=select("rc1")

Thanks
 
Upvote 0

Forum statistics

Threads
1,216,110
Messages
6,128,890
Members
449,477
Latest member
panjongshing

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