Using a variable as a Range Argument

Elknoxious

New Member
Joined
Oct 25, 2016
Messages
8
I'm stuck on a problem and hoping for some help.

I am trying to use a variable as a range argument. My goal is to loop through a range of values in another worksheet and when a value is reached copy that row and paste it to another worksheet.

The row contains several formats including a link to a webpage.

Sheetname simply designates the corresponding sheet name based on user input.

What I know works:

Code:
Worksheets(SheetName).Range("B4:H4").Copy
    Worksheets("Calculation").Range("A28:G28").PasteSpecial Paste:=xlPasteAll

However, I would like to input variables into the range argument in Sheetname.

I've tried to create string variables:

Code:
minRow = "B" & irow
maxRow = "H" & irow

and

Code:
Worksheets(SheetName).Range("minRow:maxRow").Copy
    Worksheets("Calculation").Range("A28:G28").PasteSpecial Paste:=xlPasteAll

When I print the variables they look correct but I get an error: " Run-time error '1004': " etc.

I've also tried using range and cells together but without success.

I would be grateful of any information regarding what I am doing wrong.

Thank you MrExcel community.
 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,213,551
Messages
6,114,268
Members
448,558
Latest member
aivin

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