我的变量y有问题。当我试图运行宏时,我正在接下来没有For错误。
Dim y As Long
Dim Lastrow As Long
Lastrow = Sht1.Cells(Sht1.Rows.Count, "B").End(xlUp).Row
For Each cell In sht3.Columns("B").Select
If Not IsEmpty(ActiveCell.Value) Then
With Outmail
.to = ActiveCell.Offset(ColumnOffset:=1)
.Subject = "OE input sheet " & ActiveCell.Value & ": Service Delivered = NO"
.body = "Hello " & ActiveCell.Offset(ColumnOffset:=-1).Value & vbNewLine & vbNewLine & "Test" & vbNewLine & vbNewLine
For y = 2 To Lastrow
Sht1.Range("B" & y).Select
If Application.WorksheetFunction.Match(ActiveCell.Value, sht3.Range("B:B"), 0) Then
.body = ActiveCell.Offset(ColumnOffset:=-1).Value
Next y
.Send
End With
On Error GoTo 0
Set Outmail = Nothing
End If
Next cell
提前致谢
答案 0 :(得分:0)
Dim y As Long
Dim Lastrow As Long
Lastrow = Sht1.Cells(Sht1.Rows.Count, "B").End(xlUp).Row
For Each cell In sht3.Columns("B").Select
If Not IsEmpty(ActiveCell.Value) Then
With Outmail
.to = ActiveCell.Offset(ColumnOffset:=1)
.Subject = "OE input sheet " & ActiveCell.Value & ": Service Delivered = NO"
.body = "Hello " & ActiveCell.Offset(ColumnOffset:=-1).Value & vbNewLine & vbNewLine & "Test" & vbNewLine & vbNewLine
For y = 2 To Lastrow
Sht1.Range("B" & y).Select
If Application.WorksheetFunction.Match(ActiveCell.Value, sht3.Range("B:B"), 0) Then
.body = ActiveCell.Offset(ColumnOffset:=-1).Value
End If
Next y
.Send
End With
On Error GoTo 0
Set Outmail = Nothing
Next cell