VBA : 如何获取excel自动筛选的所有值

用代码筛选并获取这几个值?
2024-12-16 06:22:55
推荐回答(2个)
回答1:

Sub test()
Dim xStr() As String
Dim i, j As Integer
Dim xRng As Range
Set xRng = Range("F1:F100") '请自己按需修改
xRng.Offset(0, 1).Insert shift:=xlToRight
xRng.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=xRng.Range("A1").Offset(0, 1), Unique:=True
j = xRng.Range("A1").Offset(60000, 1).End(xlUp).Row
ReDim xStr(j - xRng.Range("A1").Row)
For i = 1 To j - xRng.Range("A1").Row
xStr(i) = xRng.Range("A1").Offset(i, 1)
MsgBox xStr(i)
Next i
xRng.Offset(0, 1).Delete shift:=xlToLeft
End Sub

回答2:

http://www.12124.com/ruanjianwenti/2010420/8788.html