Simple (I think) VBA syntax question

Asala42

Well-known Member
Joined
Feb 26, 2002
Messages
2,318
Hey all,

Kind of a general syntax question but it's simple enough to explain. This may remind you of the INDIRECT function.

The Brief History:
Somewhere in my current code I have an Object Variable (I'll call "x") that eventually gets assigned an integer value (via a calculation). The code I have so far to get this integer value works great. My question relates to the next step.

By design, the end value for X is actually a row number. For example sake, say the current code ends in setting X = 34. What I'd like to do is use that Object Variable as a way to select a cell in Column B (B34 in this example). How do you code this?

I've tried (with dismal failure) code similar to this:

Range("B:"&X).Select (or)
Range(""B:"&X").Select

...I know I'm missing something really basic - but I'm starting to go NUTS!

Thanks!
Adam S.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
On 2002-02-27 13:44, Asala42 wrote:
Hey all,

Kind of a general syntax question but it's simple enough to explain. This may remind you of the INDIRECT function.

The Brief History:
Somewhere in my current code I have an Object Variable (I'll call "x") that eventually gets assigned an integer value (via a calculation). The code I have so far to get this integer value works great. My question relates to the next step.

By design, the end value for X is actually a row number. For example sake, say the current code ends in setting X = 34. What I'd like to do is use that Object Variable as a way to select a cell in Column B (B34 in this example). How do you code this?

I've tried (with dismal failure) code similar to this:

Range("B:"&X).Select (or)
Range(""B:"&X").Select

...I know I'm missing something really basic - but I'm starting to go NUTS!

Thanks!
Adam S.

Range("B:"&X).Select ' should work without the Colon

Range("B"&X).Select ' or use.Activate

If you are still having problems try stepping through the code to make sure that the variable x IS being assigned a value.
 
Upvote 0

Forum statistics

Threads
1,214,618
Messages
6,120,544
Members
448,970
Latest member
kennimack

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