我的工作簿中有两张工作表。我使用以下 VBA 代码来过滤数据:
Sub apply_autofilter_across_worksheets()
'Updateby Extendoffice 20160623
Dim xWs As Worksheet
On Error Resume Next
For Each xWs In Worksheets
xWs.Range("A4").AutoFilter 1, "=001"
Next
End Sub
现在我想用单元格F1中的值代替001。我该如何修改代码?
答案1
这很简单,试试看:
Sub apply_autofilter_across_worksheets()
' Updateby Extendoffice 20160623
Dim xWs As Worksheet
On Error Resume Next
For Each xWs In Worksheets
xWs.Range("A4").AutoFilter FIELD:=1, CRITERIA1:=xWs.range("F1").value
Next
End Sub
干杯