variable for cell reference

tahoney

New Member
Joined
Nov 11, 2005
Messages
7
just found this board and looks like a great place to ask for help. How can I use a variable like x for cell reference example: (bx:sx) were x is a number between 5 and 15? Is this possible? I can't seem to find any answer in the help section of excel. Thanks for any and all help.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
tahoney said:
just found this board and looks like a great place to ask for help. How can I use a variable like x for cell reference example: (bx:sx) were x is a number between 5 and 15? Is this possible? I can't seem to find any answer in the help section of excel. Thanks for any and all help.

Like this --

Dim x as Integer, Rng as Range
x = 11
Set Rng = Range("A" & x & ":B" & x)
 
Upvote 0
just_jon said:
tahoney said:
just found this board and looks like a great place to ask for help. How can I use a variable like x for cell reference example: (bx:sx) were x is a number between 5 and 15? Is this possible? I can't seem to find any answer in the help section of excel. Thanks for any and all help.

Like this --

Dim x as Integer, Rng as Range
x = 11
Set Rng = Range("A" & x & ":B" & x)

just_jon thats is just what i needed thanks very much
 
Upvote 0
Perhaps you were looking for --

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> foo()
<SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>
<SPAN style="color:#00007F">For</SPAN> i = 1 <SPAN style="color:#00007F">To</SPAN> Cells(Rows.Count, 1).End(xlUp).Row
    Cells(i, "a") = Cells(i, "a") + i
    Cells(i, 2) = Cells(i, 2) / i
<SPAN style="color:#00007F">Next</SPAN> i
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 
Upvote 0

Forum statistics

Threads
1,203,455
Messages
6,055,540
Members
444,794
Latest member
HSAL

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