答案1
Selections 不会给您带来任何好处。Selection 和 ActiveSheet 的使用并不安全。
必须定义变量
Dim sheet1 As Worksheet, sheet2 As Worksheet
Dim range1 As Range, range2 As Range
然后获取并使用对工作表和范围的引用。例如:
Set sheet1 = ThisWorkbook.Sheets("Sheet1")
Set range1 = ThisWorkbook.Sheets("Sheet2").Range("T8")
sheet1.Range("$A:$CT").AutoFilter Field:=16, Criteria1:=range1.Value
或者
Set range1 = ThisWorkbook.Sheets("Sheet1").Range("$A:$CT")
Set range2 = ThisWorkbook.Sheets("Sheet2").Range("T8")
range1.AutoFilter Field:=16, Criteria1:=range2.Value
或者
Set sheet1 = ThisWorkbook.Sheets("Sheet1")
Set sheet2 = ThisWorkbook.Sheets("Sheet2")
sheet1.Range("$A:$CT").AutoFilter Field:=16, Criteria1:=sheet2.Range("T8").Value
等等...