改为将我的答案更改为以下内容。不是最好的解决方案,因为使用 SpecialCells 充其量是棘手的,但这可能非常适合您的需求。
Sub Illusion()
Dim Source, Dummy As Worksheet
Dim SRow, LRow As Long
Application.ScreenUpdating = False
With ThisWorkbook
Set Source = .ActiveSheet
Set Dummy = .Sheets.Add(After:=Sheets(Sheets.Count))
End With
SRow = 8
LRow = Range("H4").Value + 1
'Change the H10000 below to the correct end row of your unfiltered table.
Source.Range("B" & SRow & ":H10000").SpecialCells(xlCellTypeVisible).Copy
With Dummy
'We create an illusion that we copy only the names we need by bridging using a dummy sheet and copying from there.
.Range("A1").PasteSpecial xlPasteValues
.Range("A1:A" & LRow).Copy
'Paste to desired location as values as well.
.Delete
End With
Application.ScreenUpdating = True
End Sub
我在这里所做的是,我们将可见单元格复制到一个虚拟表中,调整要从该虚拟表中复制的名称数量并使用它做任何您想做的事情,然后删除该虚拟表。这是一个快速和肮脏的,但它胜过不得不去复杂的 SpecialCells。