+ Reply to Thread
Results 1 to 8 of 8

Filter data that changes everyday to a new excel workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    09-19-2017
    Location
    Riga, Latvia
    MS-Off Ver
    MS Office 16
    Posts
    4

    Filter data that changes everyday to a new excel workbook

    Hello,

    So is have a backlog file with vendors that needs to be filtered one by one vendor, pastate each line with specific vendor data to new excel workbook and save it in folder.

    The problem is, i do not know how to clarify filter criteria, as the vendors in excel changes every day.

    Should i make it with if criteria including every vendor?

    Thank you in advance.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by Nadina; 11-28-2017 at 05:52 AM.

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: Filter data that changes everyday to a new excel workbook

    Use Dictionary to extract unique vendor names and then loop through Dictionary elements to apply Autofilter to Filter, Copy to new workbook.

    Attach sample workbook if you need code to do so.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Registered User
    Join Date
    09-19-2017
    Location
    Riga, Latvia
    MS-Off Ver
    MS Office 16
    Posts
    4

    Re: Filter data that changes everyday to a new excel workbook

    I have attached excel to my original post.
    Last edited by Nadina; 11-28-2017 at 05:53 AM.

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: Filter data that changes everyday to a new excel workbook

    This should do it.

    Sub Create_Sheets()
        Dim fName As String
        Application.ScreenUpdating = False
        MainFolderPath = "D:\Nadina" & "\"
        sn = Sheet1.Cells(1).CurrentRegion.Value
        Set dic = CreateObject("scripting.dictionary")
        For i = 2 To UBound(sn)
            x0 = dic.Item(sn(i, 2))
        Next
        For j = 0 To dic.Count - 1
            fName = dic.keys()(j)
            fName = RemoveIllegalCharacters(fName)
            With Sheet1
                .Cells(1).CurrentRegion.AutoFilter 2, dic.keys()(j)
                .AutoFilter.Range.SpecialCells(xlCellTypeVisible).Copy Sheets("Temp").Range("A1")
            End With
            With Sheets("Temp")
                With .Cells(1).CurrentRegion
                    .EntireColumn.AutoFit
                    .EntireRow.AutoFit
                End With
                .Copy
            End With
            With ActiveWorkbook
                Sheets(1).Name = fName
                .SaveAs MainFolderPath & fName, 51
                .Close
            End With
            Sheets("Temp").Cells(1).CurrentRegion.ClearContents
        Next
        Sheet1.ShowAllData
        Application.ScreenUpdating = True
    End Sub
    
    Public Function RemoveIllegalCharacters(ByVal strText As String) As String
    
        Const cstrIllegals As String = "\,/,:,*,?,"",<,>,|,."
        Dim lngCounter As Long
        Dim astrChars() As String
        astrChars() = Split(cstrIllegals, ",")
        For lngCounter = LBound(astrChars()) To UBound(astrChars())
            strText = Replace(strText, astrChars(lngCounter), "_")
        Next lngCounter
        RemoveIllegalCharacters = strText
    
    End Function
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    09-19-2017
    Location
    Riga, Latvia
    MS-Off Ver
    MS Office 16
    Posts
    4

    Re: Filter data that changes everyday to a new excel workbook

    Thank you for the code.

    I Run into Error, for line
    For i = 2 To UBound(sn)
    It shows as "type mismatch". Could you please advise?

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: Filter data that changes everyday to a new excel workbook

    All works fine for me in your example file so did you try that or did you put the code in a different file ?

  7. #7
    Registered User
    Join Date
    09-19-2017
    Location
    Riga, Latvia
    MS-Off Ver
    MS Office 16
    Posts
    4

    Re: Filter data that changes everyday to a new excel workbook

    Yes, i found the problem. I am sorry that i keep asking question, but i have one more.
    As i have little encounter with Dictionary, i am new to this and learn as i go.
    How can i change that it takes not the vendor names from the second column, but their number from the first column?
    I tried to change it myself but i messed it up in the end.

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: Filter data that changes everyday to a new excel workbook

    The files are now also named by vendor numbers. Let me know if you want them by name.

    Sub Create_Sheets()
        Dim fName As String
        Application.ScreenUpdating = False
        MainFolderPath = "D:\Nadina" & "\"
        sn = Sheet1.Cells(1).CurrentRegion.Value
        Set dic = CreateObject("scripting.dictionary")
        For i = 2 To UBound(sn)
            x0 = dic.Item(sn(i, 1))
        Next
        For j = 0 To dic.Count - 1
            With Sheet1
                .Cells(1).CurrentRegion.AutoFilter 1, dic.keys()(j)
                .AutoFilter.Range.SpecialCells(xlCellTypeVisible).Copy Sheets("Temp").Range("A1")
            End With
            With Sheets("Temp")
                With .Cells(1).CurrentRegion
                    .EntireColumn.AutoFit
                    .EntireRow.AutoFit
                End With
                .Copy
            End With
            With ActiveWorkbook
                Sheets(1).Name = dic.keys()(j)
                .SaveAs MainFolderPath & dic.keys()(j), 51
                .Close
            End With
            Sheets("Temp").Cells(1).CurrentRegion.ClearContents
        Next
        Sheet1.ShowAllData
        Application.ScreenUpdating = True
    End Sub

+ 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. Copy/update data from one workbook to another everyday automatically
    By abby123 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-08-2017, 11:04 AM
  2. NEED HELP. Save workbook multiple time with everyday of the month.
    By Tyger0951 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-07-2014, 04:49 AM
  3. Excel VBA filter to criteria and copy data and paste to another workbook
    By aalvaro03 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-19-2013, 07:33 PM
  4. [SOLVED] Copying data from a closed workbook into an open workbook ignoring excel filter?
    By reach78 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 09-17-2013, 12:31 AM
  5. Filter data on seperate workbook and paste on current workbook
    By ZeDoctor in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-28-2012, 08:08 AM
  6. update masterfile with data from everyday new excel file with date stamp in name
    By Sameem in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-18-2010, 12:42 PM
  7. Copy data from new everyday csv file to next empty row in master excel file
    By hablu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-18-2009, 02:06 AM

Tags for this Thread

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