我有2个电子表格:
main.xlsx
和
drs.xlsx
他们需要加入,但在加入之前我需要在drs.xlsx上使用VBA过滤掉一些行。
当在main.xlsx上按下按钮时,如何根据以下条件过滤掉drs.xslx上的行(即忽略任何不符合此条件的内容):
Column A = "TW" or "W"
Column C = "Windows 7" or "Windows XP"
Column D = "Workstation-Windows"
答案 0 :(得分:1)
这是你需要的吗?
Sub test()
Dim wb As Workbook
'if drs is already opened
Set wb = Workbooks("drs.xlsx")
'if drs not already opened
'Set wb = Workbooks.Open("C:\drs.xlsx")
With wb.Worksheets("Sheet1")
.AutoFilterMode = False
With .Range("A1:D1")
.AutoFilter Field:=1, Criteria1:="TW", Operator:=xlOr, Criteria2:="W"
.AutoFilter Field:=3, Criteria1:="Windows 7", Operator:=xlOr, Criteria2:="Windows XP"
.AutoFilter Field:=4, Criteria1:="Workstation-Windows"
End With
End With
End Sub
选择形状,比方说。矩形:
创建按钮,并向其添加文字:
指定宏: