Referencing rows within a loop

brandonlyz

New Member
Joined
May 11, 2014
Messages
5
Hi all,

My issue comes about when I'm trying to copy data from certain rows within a sheet, where the location of the rows is directly related to the value during the particular loop process. However, this gives me a Method'Range of object'_Worksheet' failed error.

If you're confused, here's an example of my code:

Code:
For pnumber = 0 To 16
r_copy = 2 + 17 * pnumber
c_copy = 18 + 17 * pnumber
Sheet3.Range("2:18") = Sheet2.Range("r_copy:c_copy")

Do ask if you any other questions, and I will be more than glad to answer them. Thanks for reading.

Ps: This is being run by a userform.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi,

The problem is situated here:
Code:
Sheet3.Range("2:18") = Sheet2.Range("r_copy:c_copy")</pre>

You can only enter cells in the form like A1 in range like that.
You could however.
Code:
Sheet3.Cells(2,18) = Sheet2.Cells(r_copy,c_copy)
</pre>
 
Upvote 0

Forum statistics

Threads
1,223,727
Messages
6,174,146
Members
452,547
Latest member
Schilling

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