我设置了这个代码,我让它在一张纸上使用自动过滤器搜索某些名称,然后如果名称在那里,那么它将复制工作表上的所有可见单元格,然后将其粘贴到不同工作表上的定义范围。代码将识别出我希望它搜索的名称在那里,当我分解代码时,它会复制范围,但是当我让它插入复制的范围时,它只是插入一个空白行而不是复制的范围。一直在旋转我的轮子,试图找出它为什么不起作用。任何帮助表示赞赏。
Sub UpdateEmail()
Dim dstSheet As Worksheet
Dim srcSheet As Worksheet
Dim srcRng As Range
Dim lRow As Long
Set srcRng2 = Sheets("Paste").Range("G:G")
With ThisWorkbook
Set srcSheet = .Sheets("Paste")
Set dstSheet = .Sheets("Email")
End With
'John Update
Set rngJohn = srcRng2.Find("*" & "John" & "*")
If rngJohn Is Nothing Then
MsgBox "No deals for John Doe"
Application.DisplayAlerts = True
Else
With srcSheet
lRow = .Cells(Rows.Count, 1).End(xlUp).Row
.Rows(1).AutoFilter 7, "*" & "John" & "*"
Set srcRng = .Range(.Cells(2, 1), .Cells(lRow, 8))
srcRng.SpecialCells(xlCellTypeVisible).Copy
Range("JohnRow").Insert Shift:=xlDown
End With
Application.CutCopyMode = False
srcSheet.ShowAllData
End If
'Jane Update
Set rngJane = srcRng2.Find("*" & "Jane" & "*")
If rngJane Is Nothing Then
MsgBox "No deals for Jane Doe"
Application.DisplayAlerts = True
Else
With srcSheet
lRow = .Cells(Rows.Count, 1).End(xlUp).Row
.Rows(1).AutoFilter 7, "*" & "Jane" & "*"
Set srcRng = .Range(.Cells(2, 1), .Cells(lRow, 8))
srcRng.SpecialCells(xlCellTypeVisible).Copy
Range("JaneRow").Insert Shift:=xlDown
End With
Application.CutCopyMode = False
srcSheet.ShowAllData
End If
'Jeff Update
Set rngJeff = srcRng2.Find("*" & "Jeff" & "*")
If rngJeff Is Nothing Then
MsgBox "No deals for Jeff"
Application.DisplayAlerts = True
Else
With srcSheet
lRow = .Cells(Rows.Count, 1).End(xlUp).Row
.Rows(1).AutoFilter 7, "*" & "Jeff" & "*"
Set srcRng = .Range(.Cells(2, 1), .Cells(lRow, 8))
srcRng.SpecialCells(xlCellTypeVisible).Copy
Range("JeffRow").Insert Shift:=xlDown
End With
Application.CutCopyMode = False
srcSheet.ShowAllData
End If
End Sub


