[已解决]VBA筛选某列包含的数据复制到另一个表中去?
本帖最后由 hhxq001 于 2021-3-6 19:40
xdragon 发表于 2016-4-22 16:50
你代码最后的with ... end with 那段改为这个就行了
不知道你是什么版本的excel,如果03以上这个代码应该 ...
大侠,我用你的这段代码的时候,提示对象变量或with未设置,怎么解决?
Sub 导出()
Dim i, k As Integer
Dim rg As Range
Dim t
t = Timer
Application.ScreenUpdating = False
Sheets('基数').Activate
k = 1
'Set rg = Range('A1:w1')
For i = 4 To Cells(Rows.Count, 4).End(xlUp).Row
If Range('B'& i) Like '*王*' Then
If rg Is Nothing Then
Set rg = Range('A'& i& ':w'& i)
Else
Set rg = Union(rg, Range('A'& i& ':w'& i))
End If
End If
Next i
With Workbooks.Add
rg.Copy.ActiveSheet.Range ('A2')
.SaveAs (ThisWorkbook.Path& '\123.xlsx')
End With
Application.ScreenUpdating = True
MsgBox '用时:'& Format(Timer - t, '0.000000s')
End Sub