Copying Non-Contiguous Range from one Worksheet to another

cappla011

New Member
Joined
Mar 13, 2013
Messages
24
So this might be a basic question, but after a decent amount of time researching the forums and internet, I can't seem to find a decent answer. I'm copying a range of cells from one workbook to another, but some columns on the Master workbook I don't need, so I'm skipping. To do this, I'm using a Do Until statement, and am doing it 3 different for each contiguous range. Cutting out most of the non-related coding, it currently looks like this --

Code:
Dim Counter, CycleCounter, As Integer

Counter = 21
RowCounter = 3

'This Do Until statement makes it stop when the background color turns yellow, which in my Master sheet means it is the end of data
Do Until Master.Sheets("ZZANALYSIS_PATTERN").Cells(Counter, 1).Interior.ColorIndex = 6

'This copies the data from the Master to the new workbook
ThisWorkbook.Sheets("Sheet4").Range("A" & RowCounter, "D" & RowCounter).Value = Master.Sheets("ZZANALYSIS_PATTERN").Range("A" & Counter, "D" & Counter).Value

RowCounter = RowCounter + 1
Counter = Counter + 1

Loop


Then I do it again, but with a different Range -

Code:
Counter = 21
RowCounter = 3

'This  Do Until statement makes it stop when the background color turns  yellow, which in my Master sheet means it is the end of data
Do Until Master.Sheets("ZZANALYSIS_PATTERN").Cells(Counter, 1).Interior.ColorIndex = 6

'This copies the data from the Master to the new workbook
ThisWorkbook.Sheets("Sheet4").Range("E" & RowCounter, "F" & RowCounter).Value = Master.Sheets("ZZANALYSIS_PATTERN").Range("G" & Counter, "H" & Counter).Value

RowCounter = RowCounter + 1
Counter = Counter + 1

Loop


Then one more time -

Code:
Counter = 21
RowCounter = 3

'This  Do Until statement makes it stop when the background color turns  yellow, which in my Master sheet means it is the end of data
Do Until Master.Sheets("ZZANALYSIS_PATTERN").Cells(Counter, 1).Interior.ColorIndex = 6

'This copies the data from the Master to the new workbook
ThisWorkbook.Sheets("Sheet4").Range("G" & RowCounter, "H" & RowCounter).Value = Master.Sheets("ZZANALYSIS_PATTERN").Range("O" & Counter, "P" & Counter).Value

RowCounter = RowCounter + 1
Counter = Counter + 1

Loop



If I could figure out a way to make the code -

Code:
ThisWorkbook.Sheets("Sheet4").Range("A" & RowCounter, "D" &  RowCounter).Value = Master.Sheets("ZZANALYSIS_PATTERN").Range("A" &  Counter, "D" & Counter).Value

include all the of the ranges, I wouldn't have to run this Do Until 3 different times. It goes through a large amount of data and takes a tiny bit of length to run, so if I could get it to include all of the ranges, I could drop the time it takes to run by 66%.

Hope this makes sense, if you could help it would be greatly appreciated. Thanks.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Code:
Dim Counter, CycleCounter, As Integer


Counter = 21
RowCounter = 3


'This Do Until statement makes it stop when the background color turns yellow, which in my Master sheet means it is the end of data
Do Until Master.Sheets("ZZANALYSIS_PATTERN").Cells(Counter, 1).Interior.ColorIndex = 6


'This copies the data from the Master to the new workbook
ThisWorkbook.Sheets("Sheet4").Range("A" & RowCounter, "D" & RowCounter).Value = Master.Sheets("ZZANALYSIS_PATTERN").Range("A" & Counter, "D" & Counter).Value
ThisWorkbook.Sheets("Sheet4").Range("E" & RowCounter, "F" & RowCounter).Value = Master.Sheets("ZZANALYSIS_PATTERN").Range("G" & Counter, "H" & Counter).Value
ThisWorkbook.Sheets("Sheet4").Range("G" & RowCounter, "H" & RowCounter).Value = Master.Sheets("ZZANALYSIS_PATTERN").Range("O" & Counter, "P" & Counter).Value


RowCounter = RowCounter + 1
Counter = Counter + 1


Loop
 
Upvote 0
Is this what you looking for ?

Code:
Counter = 21
RowCounter = 3


'This Do Until statement makes it stop when the background color turns yellow, which in my Master sheet means it is the end of data
Do Until Master.Sheets("ZZANALYSIS_PATTERN").Cells(Counter, 1).Interior.ColorIndex = 6


'This copies the data from the Master to the new workbook
ThisWorkbook.Sheets("Sheet4").Range("A" & RowCounter, "D" & RowCounter).Value = Master.Sheets("ZZANALYSIS_PATTERN").Range("A" & Counter, "D" & Counter).Value
ThisWorkbook.Sheets("Sheet4").Range("E" & RowCounter, "F" & RowCounter).Value = Master.Sheets("ZZANALYSIS_PATTERN").Range("G" & Counter, "H" & Counter).Value
ThisWorkbook.Sheets("Sheet4").Range("G" & RowCounter, "H" & RowCounter).Value = Master.Sheets("ZZANALYSIS_PATTERN").Range("O" & Counter, "P" & Counter).Value




RowCounter = RowCounter + 1
Counter = Counter + 1


Loop
 
Upvote 0
Well... I am extremely embarrassed. Thank you for the dose of common sense (and help). DOH!

But for real, thanks!
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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