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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
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,215,980
Messages
6,128,075
Members
449,418
Latest member
arm56

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