VBA: copying ranges into ranges with criteria ?

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
788
Office Version
  1. 365
Platform
  1. Windows
Hi,
i have a list of data on sheet("data") in columns A:C in the following format:


[TABLE="class: s570a4-19 MzlEq"]
<tbody>[TR="class: s570a4-20 bKSoXW"]
[TH="class: s570a4-25 eCDbZz, align: center"]OrderNumber[/TH]
[TH="class: s570a4-25 eCDbZz, align: center"]Quantity[/TH]
[TH="class: s570a4-25 eCDbZz, align: center"]CountryCode[/TH]
[/TR]
[TR="class: s570a4-20 bKSoXW"]
[TD="class: s570a4-21 fyFZeq"]0001[/TD]
[TD="class: s570a4-21 fyFZeq"]12[/TD]
[TD="class: s570a4-21 fyFZeq"]01[/TD]
[/TR]
[TR="class: s570a4-20 bKSoXW"]
[TD="class: s570a4-21 fyFZeq"]0002[/TD]
[TD="class: s570a4-21 fyFZeq"]1[/TD]
[TD="class: s570a4-21 fyFZeq"]01[/TD]
[/TR]
[TR="class: s570a4-20 bKSoXW"]
[TD="class: s570a4-21 fyFZeq"]0003[/TD]
[TD="class: s570a4-21 fyFZeq"]4[/TD]
[TD="class: s570a4-21 fyFZeq"]02[/TD]
[/TR]
[TR="class: s570a4-20 bKSoXW"]
[TD="class: s570a4-21 fyFZeq"]0004[/TD]
[TD="class: s570a4-21 fyFZeq"]1[/TD]
[TD="class: s570a4-21 fyFZeq"]03[/TD]
[/TR]
[TR="class: s570a4-20 bKSoXW"]
[TD="class: s570a4-21 fyFZeq"]0005[/TD]
[TD="class: s570a4-21 fyFZeq"]6[/TD]
[TD="class: s570a4-21 fyFZeq"]04[/TD]
[/TR]
[TR="class: s570a4-20 bKSoXW"]
[TD="class: s570a4-21 fyFZeq"]0006[/TD]
[TD="class: s570a4-21 fyFZeq"]1[/TD]
[TD="class: s570a4-21 fyFZeq"]04[/TD]
[/TR]
</tbody>[/TABLE]


I need to copy everything with CountryCode 01 into range "label01" on Sheet("Labels") and repeat for each country code. I usually do this manually with copy/paste values but its very repetitive.

Though if there are more than 10 with same country code, rest will go on to the following label.
(label ranges are 3col x 10row)

example:


CountryCode: 01 - 6 rows (goes into range "label01")
CountryCode: 02 - 14 rows (10 goes into "label02" and 4 goes into "label03"
CountryCode: 03 - 8 rows (goes into "label04")


I dont know how difficult this is, but any pointers on how i could go about this would be appreciated.
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Just curious, why do you truncate your named ranges at 10 rows? Seems to defeat the purpose of naming them with suffixes that are country codes if you end up with country code 03 data going to label04 rather than label03.
 
Last edited:
Upvote 0
Just curious, why do you truncate your named ranges at 10 rows? Seems to defeat the purpose of naming them with suffixes that are country codes if you end up with country code 03 data going to label04 rather than label03.

Thanks for the reply
It's because the labels are produced from sticker sheets and only 10 rows of data fit on each label.

So the label named ranges are totally unrelated to the country codes (should have probably named them differently)
 
Last edited:
Upvote 0
Cross posted https://www.ozgrid.com/forum/forum/...-copying-ranges-into-ranges-based-on-criteria

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,180
Members
452,615
Latest member
bogeys2birdies

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