+ Reply to Thread
Results 1 to 2 of 2

Macro Loop: Creating multiple workbook based on autofilter criteria

  1. #1
    Registered User
    Join Date
    11-23-2016
    Location
    Manila, Philippines
    MS-Off Ver
    MS Office 2010
    Posts
    1

    Macro Loop: Creating multiple workbook based on autofilter criteria

    I have a master file where the data of all Team Managers are saved. What Im trying to do is to separate each Team Managers' data into different workbook where it should have their name as the filename.
    I created another tab in the master file called "Manager_List" - this contains the name of the managers as the Criteria from A2 to A10 as an example.
    When I run my current script, it loops to the same Criteria which in A2 under the "Manager_List" tab. So it keeps on doing the same thing over and over again. After saving the first file, i want it to go to the next Criteria in A3, then A4, then A5 so on...
    Please help!

    Sub Macro3()

    Do
    'This part should autofilter the data based on the names in the "Manager_List" tab
    Selection.AutoFilter Field:=2, Criteria1:=Worksheets("Manager_List").Range("A2").Value
    'After it filters the data, it will copy and paste to a new workbook
    Range("A1:W1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Workbooks.Add
    ActiveSheet.Paste
    Columns("A:A").Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
    Columns("A:V").Select
    Columns("A:V").EntireColumn.AutoFit

    Application.DisplayAlerts = False
    Sheets(Array("Sheet2", "Sheet3")).Select
    Sheets("Sheet3").Activate
    ActiveWindow.SelectedSheets.Delete
    Application.DisplayAlerts = True
    Range("A1").Select
    'This part will save the new workbook that contains the data of specific team manager.
    'After saving it should close the new workbook and go back to the master file
    Dim Path As String
    Dim filename As String
    Path = "C:\Users \Documents\Sept Results_"filename = Range("A2")
    ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsb", FileFormat:=50
    ActiveWindow.Close
    'Id like it to run again to the next cell in (Criteria1:=Worksheets("Manager_List").Range("A2").Value) - so that should be A3 until it reaches the blank cell before it stops.
    Loop Until ActiveCell.Value = ""
    End Sub

  2. #2
    Valued Forum Contributor kasan's Avatar
    Join Date
    07-22-2009
    Location
    Riga, Latvia
    MS-Off Ver
    Excel 2010
    Posts
    680

    Re: Macro Loop: Creating multiple workbook based on autofilter criteria

    You have Do ... Loop with constant values inside. This one does not ever stop, right?
    Declare some variable, lets say
    Please Login or Register  to view this content.
    Your criteria are in A2, A3... so before Do Loop starts:
    Please Login or Register  to view this content.
    AND
    Please Login or Register  to view this content.
    ...
    Please Login or Register  to view this content.
    AND make sure that cycle will take next criteria:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro Autofilter same criteria across multiple columns
    By Kungfubarbie in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-07-2014, 04:35 AM
  2. [SOLVED] vba copy and paste based on multiple loop criteria
    By sarahcpa in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-19-2013, 10:29 AM
  3. Replies: 1
    Last Post: 01-06-2012, 06:18 AM
  4. Copy and paste autofilter data based on multiple criteria to another worksheet
    By loneman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2012, 03:05 PM
  5. Hide and Autofilter Macro based on Criteria
    By dawnmau in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 09-22-2010, 05:45 PM
  6. Replies: 3
    Last Post: 07-21-2009, 02:16 PM
  7. [SOLVED] Extracting content based on criteria and creating new workbook
    By Gary J. Dikkema in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-17-2006, 03:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1