Macros to filter for each Unique Value

KJP13

New Member
Joined
Sep 17, 2015
Messages
24
Hi,

I am trying to create a macro to copy data from one excel workbook to another. I need to do this for each name listed. There may be multiple lines for each name so must filter for each name and copy all data.

The list of names will differ each day that this macro is run so i cannot use the specific names in the macro. Not used macros in a long time and memory is completely failing me. Any help appreciated. Data example below


NameDateCityCountryAmountYes/No
Alex2/5/15LondonUK55No
Linda3/5/15GlasgowUK62Yes
John5/5/15BirminghamUK32No
Alex9/5/15LondonUK22Yes
Leo10/5/15EdinburghUK36Yes
Alex15/5/15NottinghamUK99No

<tbody>
</tbody>

Result should be 4 individual work books, 1 for Alex with 3 lines, 1 for Linda with 1 line, 1 for John with 1 line and 1 for Leo with 1 line.

Thanks
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
How about
Code:
Sub SplitWbk()
   Dim Cl As Range
   Dim Ws As Worksheet
   
   Application.ScreenUpdating = False
   Set Ws = Sheets("Sheet1")
   With CreateObject("scripting.dictionary")
      If Ws.AutoFilterMode Then Ws.AutoFilterMode = False
      For Each Cl In Ws.Range("A2", Ws.Range("A" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then
            .Add Cl.Value, Nothing
            Ws.Range("A1:F1").AutoFilter 1, Cl.Value
            Workbooks.Add
            Ws.AutoFilter.Range.Copy Range("A1")
            ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & Cl.Value & ".xlsm", 52
            ActiveWorkbook.Close False
         End If
      Next Cl
      Ws.AutoFilterMode = False
   End With
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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