Richard1982
New Member
- Joined
- Jul 6, 2022
- Messages
- 11
- Office Version
- 365
- Platform
- Windows
Hello,
Really hoping someone can help me because I'm puling out my hair trying to solve this and getting no where fast.
I have a PivotTable and one of the filters is for 'Vendor Name'. I can select a vendor then click a button I made and it fires them off an e-mail full of details which have been extracted from the PivotTable. So far so good... Then I thought to myself that since I pretty much e-mail these people all at the same time (once a month, 30 vendors), I should make a loop function so I can click the button once and it e-mails everyone, by going through the 'Vendor Name' list one by one.
So I came up with this code:
Sub Click()
Dim pT As PivotTable
Dim pF As PivotField
Dim pi As PivotItem
Dim i As Long 'This is the loop counter
Workbook.RefreshAll
Set pT = ActiveSheet.PivotTables(1) 'Select the PivotTable for the loop
Set pF = pT.PivotFields("Vendor Name") 'Select the PivotField we will loop through
For i = 1 To pF.PivotItems.Count
Call EmailGP 'This is the function that makes/sends the e-mail
Next i
End Sub
I thought that would crack it, but it just tells me 'Object Required', what is it I'm missing?
Any help would be greatly appreciated.
Richard
Really hoping someone can help me because I'm puling out my hair trying to solve this and getting no where fast.
I have a PivotTable and one of the filters is for 'Vendor Name'. I can select a vendor then click a button I made and it fires them off an e-mail full of details which have been extracted from the PivotTable. So far so good... Then I thought to myself that since I pretty much e-mail these people all at the same time (once a month, 30 vendors), I should make a loop function so I can click the button once and it e-mails everyone, by going through the 'Vendor Name' list one by one.
So I came up with this code:
Sub Click()
Dim pT As PivotTable
Dim pF As PivotField
Dim pi As PivotItem
Dim i As Long 'This is the loop counter
Workbook.RefreshAll
Set pT = ActiveSheet.PivotTables(1) 'Select the PivotTable for the loop
Set pF = pT.PivotFields("Vendor Name") 'Select the PivotField we will loop through
For i = 1 To pF.PivotItems.Count
Call EmailGP 'This is the function that makes/sends the e-mail
Next i
End Sub
I thought that would crack it, but it just tells me 'Object Required', what is it I'm missing?
Any help would be greatly appreciated.
Richard