Create Workbooks from a data list using filters to select names

MikeXYZ7

New Member
Joined
Aug 11, 2017
Messages
35
Hi

I have searched for answers to this but couldn't find any. I have a list which consists of different products eg blue, red and green. There are around 10 columns (of extra info) and about 1000 lines and this info changes weekly. What i want to do is automate the process of filtering by "colour" and copying the range (10 columns by however many rows) and in doing so create 3 files....blue.xlsm, red.xlsm & green.xlsm.

The bit i am getting stuck on the most is how to automatically select the range for each filter of red, blue and green. I am sorting the colour column, then filtering to select red, copy range and paste as values in new workbook, then repeating the process for blue and green.

The trouble is that the number of rows varies and the start point row eg A column needs to be the first line of the new data.

ABCDEFGHI
1DATENAMETIMECOLOURWEIGHTHEIGHTDEPTHLENGTHGRADE
21.9
Dave0800blue1001001001001
32.9John0800blue1001001001001
41.9dave0800red505050502
53.9steve0800red606060601
63.9dior0800green445566661
75.9cath0900red223322222
81.9sarah0900green563434343
94.9james0900blue341212121

<tbody>
</tbody>

Please can one of you clever people help me out as i'm really stuck on this. End result should be 3 files that contain the rows relating to the colour eg red, blue and green.

Really would appreciate your help and i hope my explanation makes sense?

Best wishes

Mike
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Mike

If you are filtering you shouldn't need to sort.

You should just be able to filter for each unique value in the COLOUR column one by one and copy the visible cells for each colour to the relevant workbook.

Getting the range to copy/filter should be straightforward, it's the current region that contains A1 (assuming your data/headers in A1 of course).
 
Upvote 0
Mike

If you are filtering you shouldn't need to sort.

You should just be able to filter for each unique value in the COLOUR column one by one and copy the visible cells for each colour to the relevant workbook.

Getting the range to copy/filter should be straightforward, it's the current region that contains A1 (assuming your data/headers in A1 of course).

Hi Norie

Thanks for the response. What you are saying makes sense. It sounds like the beginning of my range is good eg A1: but I'm not sure how to automatically adjust for the number of rows after the filter? My end range will be something like J?? eg A1:J?? where ?? relates to the last row.

Can you help me with this part of the code please? It's late - i'll try and post the code i have so far tomorrow.

Thanks again

mike
 
Upvote 0
Mike

Something like this could be used to get the range including the header and the data.
Code:
Dim rngData As Range

    Set rngData = Range("A1").CurrentRegion

That range could then be filtered as required and the results of each filter copied to the relevant workbook.
 
Upvote 0
Hi Norie
That was remarkably simple and worked brilliantly. Thank you for your help with this. Very happy.
Kind regards
Mike
 
Upvote 0
One thing I have just noticed is that I am inadvertently copying the header rows too. Rows 1-4 contain info and headers (row 4) that i do not want to copy. I set the ranges for all macro references to A5 as a start point but it copies from row A3.

How do i get around this?

Kind regards

Mike
 
Upvote 0
One thing I have just noticed is that I am inadvertently copying the header rows too. Rows 1-4 contain info and headers (row 4) that i do not want to copy. I set the ranges for all macro references to A5 as a start point but it copies from row A3.

How do i get around this?

Kind regards

Mike


Code here (not in relation to table i posted earlier but i think you can still get the gist of what i am trying to do?)

HTML:
Sub FilterCopyRangePasteFile5()
 
Dim rngData As Range
 
'select range and then filter by colour (headers are in rows 3 and 4)
 
    ActiveSheet.Range("$A$5:$BE$1000").AutoFilter Field:=7, Criteria1:="Blue"
   
'select range
 
    Set rngData = Range("A5").CurrentRegion
    rngData.Select
    Selection.Copy
   
'Open Target File
   
    Workbooks.Open Filename:= _
        "C:\BLUE.xlsx"
 
'put cursor at A4 in new file (haven’t specified sheet yet)
 
    Range("A4").Select
   
'paste copied cells here (as values)
 
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
   
'save & close workbook
   
    ActiveWorkbook.Save
    ActiveWindow.Close
 
End Sub
 
Upvote 0
It has been approved and can be seen up in post 7.
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,235
Members
449,092
Latest member
SCleaveland

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