Splitting out data into different workbooks

JayB0730

Board Regular
Joined
Oct 22, 2014
Messages
74
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a spreadsheet that contains several columns similar to the below:

ABCDEFG
1Report Date:6/22/18
2First NameLast NameCategorySub CategoryReg CodeDist CodeArea Code
3JonDoeFruitApple1100000
4JaneDoeFruitApple1100100
5JackDoeFruitApple1100101
6MaryDoeFruitApple1100200
7JasperTestFruitApple1100201
8VeronicaTestFruitOrange1200000
9AngelTestFruitOrange1200100
10JimDoeFruitOrange1200101
11JessGrassVeggieCarrot1300000
12JuneHighVeggieCarrot1300100
13JenOneVeggieCarrot1300101

<tbody>
</tbody>


What I would like to be able to do is the following:

1. Create different workbooks (This example would result in 3 workbooks) that contain the same data where Reg Code (2 characters always) is the same.
2. Each workbook would contain the rows of information where Reg Code is the same; however, I would NOT like to include any rows containing "00" in the Area Code field.
3. Lines 1 and 2 would be copied over each time.
4. Create each file name based on "[Category]_[Sub Category]_MMMYYYY.xlsx"

TIA!
 
Last edited:
First, I would like to thank you both very much for your help. I started with Fluff's code and received an error message on the following line:
Code:
[COLOR=#333333]Ws.UsedRange.SpecialCells(xlVisible).Copy Range("A1")[/COLOR]

"Run time error 1004. Application Defined or Object Defined error". Not sure what to do from here.

This would normally default to the ActiveSheet.
Code:
Ws.UsedRange.SpecialCells(xlVisible).Copy Range("A1")
But since it is inside the With statement for the Dicionary, it might need to have the Ws variable to qualify it.
Code:
Ws.UsedRange.SpecialCells(xlVisible).Copy Ws.Range("A1")
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Thanks, really appreciate your help with this. So trying to understand the code, what does the "EMPTY" do every time you find a value that is not equal to 00?

Code:
If Cl.Value <> "00" Then Dic(CStr(Cl.Value)) = [COLOR=#ff0000]Empty[/COLOR]
 
Upvote 0
A Dictionary contains a Key & an Item. That line adds the value of the cell as the Key & leaves the Item empty
 
Upvote 0
Ok, so I can confirm via the immediate window that the dictionary is working and the values that I need to Autofilter in column 25 is being stored... However, when I step through the code
Code:
 Ws.Range("A2:Y2").AutoFilter 25, Dic.keys

then everything in the filter get's unselected, and the filter results in hiding all data. That is why i am getting blank files.

The big mystery is how to get this line of code to work. :(
 
Upvote 0
What values do you have in that column & what values do you want to exclude?
 
Upvote 0
Very similar to the sample i gave they are 2 digit codes. Here is a complete list:

01
02
03
04
05
06
21
26
07
08
27

Since you had already excluded "00" that will obviously not show up in the dictionary - which is what we want; When I filter first on the following first, everything is filtered correctly:
Code:
Ws.Range("A2:Y2").AutoFilter 23, Cl.Value
==> Column 23, right now has values "31" and "32". It filtered on 31 first, which is correct.

What happens next is interesting. When I go to filter column 25 based on this code:
Code:
Ws.Range("A2:Y2").AutoFilter 25, Dic.keys
==> it hides everything. What's interesting is when I go back to see the values in the filter for column 23, only "32" appears and is unchecked.

**NOTE, some of the codes in the dictionary (column 25) are shared between "31" and "32" in column 23 (e.g. col 23(31) col 25 (01); col 23(32) col 25 (01)
 
Last edited:
Upvote 0
Oops, missed a bit from the 2nd filter. It worked for me because there was only 1 value to filter on
Code:
Ws.Range("A2:Y2").AutoFilter 25, Dic.keys[COLOR=#ff0000], xlFilterValues[/COLOR]
 
Upvote 0
Fantastic! It's always the simple things that break things, right?
It worked like a charm. Thank you very much for all of your patience and help with this code. I'm sure I'll be back with the next iteration of this project :)

Thanks again.
-J
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,513
Messages
6,125,253
Members
449,219
Latest member
daynle

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