I am the above error with my variable erow
Sub autoemail_customer()
Dim sh As Worksheet
Dim sh3 As Worksheet
Dim o As Integer
Dim lrow As Long
Dim erow As Range
Set sh = ThisWorkbook.Sheets("Pivot")
Set sh3 = ThisWorkbook.Sheets("Email Contact")
Application.ScreenUpdating = False
lr = sh3.Range("a" & Application.Rows.Count).End(xlUp).Row - 1
For o = 2 To lr
Set erow = sh3.Range("A" & i).Value
sh.Activate
sh.Range("B1").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Customer name"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields("Customer name"). _
CurrentPage = erow
ActiveWorkbook.EnvelopeVisible = True
sh.Range("a1:h" & lr).Select
With Selection.Parent.MailEnvelope.Item
.To = Sheets("Email Contact").Range("b" & i).Value
.CC = ""
.Subject = Sheets("Email Contact").Range("a" & i).Value & "Customer invoices : Invoices Overdue"
.Display
End With
Next
End Sub
Any idea why ??
Sub autoemail_customer()
Dim sh As Worksheet
Dim sh3 As Worksheet
Dim o As Integer
Dim lrow As Long
Dim erow As Range
Set sh = ThisWorkbook.Sheets("Pivot")
Set sh3 = ThisWorkbook.Sheets("Email Contact")
Application.ScreenUpdating = False
lr = sh3.Range("a" & Application.Rows.Count).End(xlUp).Row - 1
For o = 2 To lr
Set erow = sh3.Range("A" & i).Value
sh.Activate
sh.Range("B1").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Customer name"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields("Customer name"). _
CurrentPage = erow
ActiveWorkbook.EnvelopeVisible = True
sh.Range("a1:h" & lr).Select
With Selection.Parent.MailEnvelope.Item
.To = Sheets("Email Contact").Range("b" & i).Value
.CC = ""
.Subject = Sheets("Email Contact").Range("a" & i).Value & "Customer invoices : Invoices Overdue"
.Display
End With
Next
End Sub
Any idea why ??
Last edited by a moderator: