Results 1 to 3 of 3

Auto filter based on user input with multiple choices

Threaded View

  1. #1
    Forum Contributor
    Join Date
    03-14-2013
    Location
    England
    MS-Off Ver
    2007
    Posts
    186

    Auto filter based on user input with multiple choices

    Dear all,

    I have here an example of how I might extract data from a source workbook and paste it onto a template workbook, using autofilter to find the rows that are needed. It is currently set-up to take rows that match "AREA 1" or "AREA 2" in column A, along with a number of other criteria in other columns.

    What I want to do is add into this macro, a way for the user to be able to choose the filter options will be used for column A of the source workbook. So if they want only "AREA 1", they can choose just that, or if they want "AREA 2", or perhaps both "AREA 1" & "AREA 2", or further additional options. They need to be able to specify just one, multiple, or all of the filter options with regards to column A of the source data.

    In effect what I need is a user input box or form with a dropdown menu that will give the filter choices based on column A of the source data, and then for the code that copies the data across, to do so based on which choices the user makes in the filter menu of the input box.

    I have uploaded examples of the source data workbook and the target template workbook. The macro exists within the template workbook.


    Sub Update_Figures()
    
      Dim sWb As Workbook, tWb As Workbook
      Dim sWs As Worksheet, tWs As Worksheet
      Dim sLR As Long
      Dim cNO As Long
      Dim FindMonth As String
    
      With Application
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
        .CutCopyMode = False
      End With
      
      FindMonth = MonthName(Month(Date) - 1, True)
      
      Set sWb = Workbooks("SOURCEDATAEXAMPLE.xls")
      Set sWs = sWb.Sheets("SALESEXPORT")
      Set tWb = ThisWorkbook
      Set tWs = tWb.Sheets("2013")
    
      sWs.Activate
    
      With sWs
        sLR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                          SearchDirection:=xlPrevious).Row
        .Range("A1:T" & sLR).AutoFilter Field:=1, Criteria1:="AREA 1", _
        Operator:=xlOr, Criteria2:="AREA 2"
        .Range("A1:T" & sLR).AutoFilter Field:=4, Criteria1:="SALES"
        .Range("A1:T" & sLR).AutoFilter Field:=6, Criteria1:="2013"
        .Range(.Cells(2, "C"), .Cells(sLR, "C")).SpecialCells(xlCellTypeVisible).Copy
        tWs.Range("B3").PasteSpecial xlPasteValues
        .Range(.Cells(2, "B"), .Cells(sLR, "B")).SpecialCells(xlCellTypeVisible).Copy
        tWs.Range("A3").PasteSpecial xlPasteValues
        .Range(.Cells(2, "G"), .Cells(sLR, "R")).SpecialCells(xlCellTypeVisible).Copy
        tWs.Range("C3").PasteSpecial xlPasteValues
        .ShowAllData
      End With
      
      Set tWs = tWb.Sheets("2014")
    
      With sWs
        cNO = .Rows(1).Find(FindMonth, LookAt:=xlWhole).Column
        sLR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                          SearchDirection:=xlPrevious).Row
        .Range("A1:T" & sLR).AutoFilter Field:=1, Criteria1:="AREA 1", _
        Operator:=xlOr, Criteria2:="AREA 2"
        .Range("A1:T" & sLR).AutoFilter Field:=4, Criteria1:="SALES"
        .Range("A1:T" & sLR).AutoFilter Field:=6, Criteria1:="2014"
        .Range(.Cells(2, "C"), .Cells(sLR, "C")).SpecialCells(xlCellTypeVisible).Copy
        tWs.Range("B3").PasteSpecial xlPasteValues
        .Range(.Cells(2, "B"), .Cells(sLR, "B")).SpecialCells(xlCellTypeVisible).Copy
        tWs.Range("A3").PasteSpecial xlPasteValues
        .Range(.Cells(2, "G"), .Cells(sLR, cNO)).SpecialCells(xlCellTypeVisible).Copy
        tWs.Range("C3").PasteSpecial xlPasteValues
        .ShowAllData
      End With
      
      tWs.Activate
      
      Range(Cells(1, "A"), Cells(1664, "A")).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
      
      With Application
        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
        .CutCopyMode = False
      End With
    
    End Sub

    I am looking for someone to demonstrate to me in this example, how it may be possible for the user to be able to specify, one, multiple, or all available filter options for column A of the source data, via a user input box or form.

    Hopefully I have explained clearly enough but if not, please ask me questions. If anyone could assist I would be most grateful..

    Many thanks,
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Auto filter based on input
    By AUSSIEHEDGE in forum Excel General
    Replies: 0
    Last Post: 02-20-2013, 12:32 AM
  2. Filter by User Input with multiple criteria?
    By jsabo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-10-2012, 06:19 PM
  3. Apply Auto Filter Based on Date Input by User
    By ELDAN in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2010, 09:07 PM
  4. Filter Data based on User Input
    By izet99 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-17-2009, 05:51 PM
  5. Replies: 3
    Last Post: 05-19-2005, 08:06 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