Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel VBA - Filter "Select All"

Tags:

excel

vba

I have an Excel workbook that I use to keep track of my orders for my warehouse. I have an "Open Re-Orders" tab and an "Items Needing Quote Tab". On the "Open Re-Orders" tab, Column A contains the Item Number, and Column K contains the quoted amount from the vendor that is manually entered into the spreadsheet.

On the "Items Needing Quote" tab, I have the formula below in column A, that pulls over all of the item numbers that exist on the "Open Re-Orders" tab that do not currently have a value in Column K (Quote). I then have a macro set up that filters the data by item number, and "Selects All" and then deselects 0's and BLANKS. The macro then sorts the data by their vendor number (Column C).

Formula in column A of "Items Needing Reorder" is: =IF('Open Re-Orders'!$K:$K="",'Open Re-Orders'!$A2)

When I look at the code in the macro, I see that rather than Selecting All, the macro is selecting each item number individually. I need this to Select All every time, even if item numbers have been added to the "Open Re-Orders" tab.

Thanks in advance.

Sub Refresh_Quote()

Range("A1:E1").Select

Selection.AutoFilter
ActiveSheet.Range("$A$1:$E$150").AutoFilter Field:=1, Criteria1:=Array( _
    "90000100", "90000104", "90000106", "90000109", "90000304", "90002040", "90003060", _
    "90003070", "90003075", "90003919", "90003923", "90004134", "90004211", "90004257", _
    "90004295", "90004330", "90004385", "90004415", "90004466", "90004577", "90004600", _
    "90004858", "90004859", "90004868", "90004871", "90004872", "90004901", "90004972", _
    "90004973", "90004974", "90004975", "90004976", "90005053", "90006117", "90006168", _
    "90006320", "90006322", "90006349", "90006385", "90006466", "90007751", "90009942", _
    "90092367"), Operator:=xlFilterValues
ActiveWorkbook.Worksheets("Items Needing Quote").AutoFilter.Sort.SortFields. _
    Clear
ActiveWorkbook.Worksheets("Items Needing Quote").AutoFilter.Sort.SortFields. _
    Add Key:=Range("C1:C150"), SortOn:=xlSortOnValues, Order:=xlAscending, _
    DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Items Needing Quote").AutoFilter.Sort
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With
Range("G43").Select

End Sub

like image 226
Christopher Maddox Avatar asked Mar 16 '23 01:03

Christopher Maddox


1 Answers

This is easier than you think. Just don't include the "criteria" You have ActiveSheet.Range("$A$1:$E$150").AutoFilter Field:=1, Criteria1:=Array( _

Shorten this to ActiveSheet.Range("$A$1:$E$150").AutoFilter Field:=1

Even shorter is ActiveSheet.Range("A1").AutoFilter Field:=1

like image 145
Rob Avatar answered Mar 23 '23 04:03

Rob