Excel VBA - 过滤"全选"

时间:2015-08-18 19:37:24

标签: excel vba

我有一个Excel工作簿,用于跟踪我的仓库订单。我有一个" Open Re-Orders"选项卡和"项目需要报价标签"。 在"打开重新订单"选项卡,列A包含项目编号,列K包含手动输入电子表格的供应商的报价金额。

关于"项目需要报价"选项卡,我在A列中有以下公式,它可以覆盖"打开重新订单"中存在的所有项目编号。当前在列K(引用)中没有值的选项卡。然后我有一个宏设置,按项目编号过滤数据,"选择全部"然后取消选择0和BLANKS。然后,宏按其供应商编号(C列)对数据进行排序。

"需要重新排序的项目A的A列中的公式"是: = IF('打开重新订单'!K:$ K ="",'打开重新订单'!$ A2)

当我查看宏中的代码时,我看到的是,而不是全选,宏会单独选择每个项目编号。我每次都需要选择全部,即使项目编号已添加到"打开重新订单"标签

提前致谢。

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

1 个答案:

答案 0 :(得分:3)

这比你想象的要容易。只是不要包括“标准” 你有ActiveSheet.Range("$A$1:$E$150").AutoFilter Field:=1, Criteria1:=Array( _

将此缩短为ActiveSheet.Range("$A$1:$E$150").AutoFilter Field:=1

更短的是ActiveSheet.Range("A1").AutoFilter Field:=1