Creating a Range Using Variables for row Numbers

mcgurrgurr

New Member
Joined
Aug 22, 2011
Messages
8
I am trying to create a code which will select a range and allows me to easily edit the row numbers. I have done the same type of setup with selecting a single cell value, but I am trying to expand this to a group of cells.

When I create variables to define the columns I use the following setup (there is other code, I simply cut out what seemed relevant to show:

Dim Row

Row = "12" 'set to desired row number

Range("A" & Row:"R" & Row).Select


I keep receiving an error message, but I do not understand why. If anyone can help me it would be greatly appreciated!

Thank you!

Pat
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Welcome to the board...

You almost had it, remember to concatenate back into the string after putting in the variable Row...

Range("A" & Row & ":R" & Row)

Another way

=CELLS(Row, "A").Resize(1,13)


Hope that helps.
 
Upvote 0
That is brilliant! Thanks so much. I am still getting my head around many of these more intricate details.

If I may I have one other question. I am looking to extend the use of the previous code used into a loop function so it repeats, adding 1 to the row number each time for n (let's say 5 to quantify).


Dim PasteUpdate


Sub_Codename

PasteUpdate = "18"


Range("AA" & PasteUpdate).Select
'ActiveCell.Select
ActiveCell.Offset(ColumnOffset:=1).Activate
Range("AB" & PasteUpdate & ":AH" & PasteUpdate).Select 'fix this

Selection.Copy
Range("B7").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True

End Sub



Thanks again! I truly appreciate the help!
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

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