由于某种原因,它适用于单行。但是一旦添加了变量,我就会在电子邮件中获得一堆重复。以下是我使用的编码:
'Set the last row of the dataset on the In-Month Tracker tab
Dim LastRow As Long
Dim Response As Variant
Dim StartRow As Integer
'
LastRow = wsIMTracker.Cells(wsIMTracker.Rows.Count, "N").End(xlUp).Row
StartRow = wsIMTracker.AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Row
'
'Have the user select whether or not they are sure that they want to send the emails listed
Response = MsgBox("Are you sure that you would like to send out these Compliance Audit Emails?", vbYesNo)
'
'IF dependent upon the answer given
If Response = vbNo Then
wsIMTracker.AutoFilterMode = False
MsgBox "Returning to In-Month Tracker dataset"
Range("A1").Select
Exit Sub
End If
'
'Begin to loop through the filtered data
For i = StartRow To LastRow 'Uses starting row as first row of filtered data
'Call the email creation macro for use
Call Send_Email(CSRName, SalesRep, Notes, Contract, Customer, Expected, Actual, Difference, EmailType, Email, AppOut, AuditDate, CSREmail, RepEmail, ManagerEmail)
'Call the task sending macro for use
Call Send_Task(CSRName, SalesRep, Notes, Contract, Customer, Expected, Actual, Difference, EmailType, Email, AppOut, AuditDate, CSREmail, RepEmail, ManagerEmail)
'Call the "Yes" marking macro for use to mark lines as Emailed
Call Mark_Yes(i)
'Continuous loop through to the end of the filtered dataset
Next i
'
'Completion of the Email Send macro command coding
wsIMTracker.AutoFilterMode = False
MsgBox "Email notification(s) and Shortfall follow-up reminders successfully sent to appropriate parties."
'
'Rehide worksheets
wsIMTracker.Visible = xlSheetHidden
wsDataTables.Visible = xlSheetHidden
'
'Set window to A1 of wsVM worksheet
wsVM.Range("A1").Select