EXCEL VBA - help to copy filtered data from one workbook to multiple new workbooks and save code.

Jordan2

New Member
Joined
Apr 4, 2024
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hi,
I currently have 2 steps of code which work fine but I want it to work off of one button press to take the data from one workbook to multiple other workbooks and save as per the name.
The first set of code filters it but puts them into sheets and the second set of code converts those sheets into workbooks, but it also includes the sheet which has the data on which I don't want.
If I can get some assistance on this, much appreciated.
Please see code below:

1.
VBA Code:
 Sub Filter_Data()
     
    Dim R As Integer, ADM As String, wb As Worksheet
    Set ws = ActiveSheet
    ws.Range("A1:G1").AutoFilter
    R = 1
    Do
    R = R + 1
    ADM = ws.Range("G" & R).Value
    On Error Resume Next
    If Sheets(ADM) Is Nothing Then
      ws.Range("A1:G1").AutoFilter Field:=7, Criteria1:=ADM
      ws.Range("G1").CurrentRegion.SpecialCells(xlCellTypeVisible).Copy
      Sheets.Add.Name = ADM
      Sheets(ADM).Paste
      Columns("A:G").AutoFit
      ws.ShowAllData
    End If
Loop While ws.Range("G" & R + 1).Value <> ""

End Sub

2.
VBA Code:
Sub Folder_Creation()
      Dim ws As Worksheet
      Dim wbPath As String
      wbPath = ThisWorkbook.path
      For Each ws In ThisWorkbook.Worksheets
          ws.Copy
          With ActiveWorkbook
              .SaveAs Filename:="C:\Users\Reports\" & ws.Name
              .Close
          End With
      Next
  End Sub
 
Last edited by a moderator:

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
See if you can adapt the code here for your situation.


It looks like you just need to change the destination folder for the new workbooks (destFolder string) and the column being filtered for each different name.
 
Upvote 1
Solution
See if you can adapt the code here for your situation.


It looks like you just need to change the destination folder for the new workbooks (destFolder string) and the column being filtered for each different name.
Legend! works perfectly and with the fix on the dest folder fix
Thank you so much.
 
Upvote 0

Forum statistics

Threads
1,223,882
Messages
6,175,164
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