试试这个:这将是最快的,因为它不依赖于选择,而是通过 VBA 直接操作数据
Sub CopyRows()
Dim r_src As Range, r_dst As Range
' Pick 1st row and column of table
Set r_src = Sheets("Sheet1").Range("B4")
Set r_dst = Sheets("Sheet2").Range("B4")
Dim i As Integer, j As Integer
Dim N_rows As Integer, N_cols As Integer
'Find the size of the data
N_rows = CountRows(r_src)
N_cols = CountColumns(r_src)
'Resize source range to entire table
Set r_src = r_src.Resize(N_rows, N_cols)
Dim src_vals() As Variant, dst_vals() As Variant
'Get all the values from source
src_vals = r_src.Value2
ReDim dst_vals(1 To N_rows, 1 To N_cols)
Dim k As Integer
k = 0
For i = 1 To N_rows
' Check first column
If Val(src_vals(i, 1)) >= 10 Then
' Increment count
k = k + 1
' Copy row values
For j = 1 To N_cols
dst_vals(k, j) = src_vals(i, j)
Next j
End If
Next i
' Bring rows back into destination range
If k > 0 Then
r_dst.Resize(k, N_cols).Value2 = dst_vals
End If
End Sub
Public Function CountRows(ByRef r As Range) As Integer
CountRows = r.Worksheet.Range(r, r.End(xlDown)).Rows.Count
End Function
Public Function CountColumns(ByRef r As Range) As Integer
CountColumns = r.Worksheet.Range(r.End(xlToRight), r).Columns.Count
End Function
这是我运行的一个测试用例:
前

后
