Range Selection

cosmarchy

New Member
Joined
Nov 11, 2009
Messages
13
Hi,

I have a function which takes the worksheet target cell as an argument and I need to dynamically select a range of cells.

Basically I need to return a range of cells which starts one column to the right of target and is three columns wide.

For example, if target pointed to A1 then I need a range of cells from B3 to D3.

So far I have this:
Code:
TargetCell.Offset(0, 1).Resize(0, 3)
which rather unhelpfully tells me there is an 'Application-defined or object-defined error'

Can anyone help?

Thanks
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Is TargetCell a range variable that you have declared?
Excel sometimes uses an built-in variable Target. There is also ActiveCell.

Also, you are asking it to make a range that is 0 rows high. Perhaps
Code:
ActiveCell.Offset(0, 1).Resize(1, 3).Select
is close to the syntax you want.
 
Upvote 0
Not tested, but I think you'll have probelms setting a range size to 0 rows.
Try losing the 0:

TargetCell.Offset(0, 1).Resize(, 3)

or making it a 1 if you want it to be only 1 row high:
TargetCell.Offset(0, 1).Resize(1, 3)
 
Upvote 0

Forum statistics

Threads
1,224,509
Messages
6,179,192
Members
452,893
Latest member
denay

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