How to copy pairs of data from a row that is not contiguous and paste to another sheet.

Marvalisa

New Member
Joined
Sep 20, 2014
Messages
9
I would like to set up a loop in VBA to copy pairs of data from a row where each set of pairs is not contiguous and paste the data to another worksheet.
Here is what I have and it works but is not efficient.

.Range(.Cells(r, 20), .Cells(r, 21)).Copy wsSR.Range("B14:C14")
.Range(.Cells(r, 23), .Cells(r, 24)).Copy wsSR.Range("D14:E14")
.Range(.Cells(r, 26), .Cells(r, 27)).Copy wsSR.Range("F14:G14")
.Range(.Cells(r, 29), .Cells(r, 30)).Copy wsSR.Range("H14:I14")
.Range(.Cells(r, 32), .Cells(r, 33)).Copy wsSR.Range("J14:K14")
.Range(.Cells(r, 35), .Cells(r, 36)).Copy wsSR.Range("L14:M14")
.Range(.Cells(r, 38), .Cells(r, 39)).Copy wsSR.Range("N14:O14")

Thanks for any help you may provide.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I would like to set up a loop in VBA to copy pairs of data from a row where each set of pairs is not contiguous and paste the data to another worksheet.
Does it have to be a loop?
Try replacing those 7 lines with this one.

VBA Code:
wsSR.Range("B14:O14").Value = Application.Index(.Cells, r, Array(20, 21, 23, 24, 26, 27, 29, 30, 32, 33, 35, 36, 38, 39))
 
Upvote 0
Does it have to be a loop?
Try replacing those 7 lines with this one.

VBA Code:
wsSR.Range("B14:O14").Value = Application.Index(.Cells, r, Array(20, 21, 23, 24, 26, 27, 29, 30, 32, 33, 35, 36, 38, 39))
Peter,
No, it doesn't have to be a loop. I like to keep it simple; I like to think in terms of what I would do if I had a very large data set.
You have helped me a lot and now I have more tools in my toolbox. Hopefully, I can figure out the rest of what I am doing with what you have shown me here.
Many thanks, Marvalisa
 
Upvote 0

Forum statistics

Threads
1,215,460
Messages
6,124,949
Members
449,198
Latest member
MhammadishaqKhan

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