Excel VBA error Ambiguous Name detected: Worksheet_Change

Maggy0911

New Member
Joined
Sep 21, 2017
Messages
5
I just want my 3 pivot tables to automatically refresh. I'm not sure why I keep getting this. I made sure that the data sheet is named correctly as well as all three pivot tables. Can someone help please?

Private Sub Worksheet_Change(ByVal Target As Range) Worksheets("Data").PivotTables("PivotTable1").PivotCache.Refresh
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Worksheets("Data").PivotTables("PivotTable2").PivotCache.Refresh
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Worksheets("Data").PivotTables("PivotTable3").PivotCache.Refresh
End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I just want my 3 pivot tables to automatically refresh. I'm not sure why I keep getting this. I made sure that the data sheet is named correctly as well as all three pivot tables. Can someone help please?

Private Sub Worksheet_Change(ByVal Target As Range) Worksheets("Data").PivotTables("PivotTable1").PivotCache.Refresh
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Worksheets("Data").PivotTables("PivotTable2").PivotCache.Refresh
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Worksheets("Data").PivotTables("PivotTable3").PivotCache.Refresh
End Sub
You can only have one procedure with any given name in a module... you have the Worksheet_Change event procedure name using three times... that is why you get the Ambiguous Name error... the compiler does not know which one to use. Put all of your code into a single procedure like this...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Worksheets("Data").PivotTables("PivotTable1").PivotCache.Refresh
  Worksheets("Data").PivotTables("PivotTable2").PivotCache.Refresh
  Worksheets("Data").PivotTables("PivotTable3").PivotCache.Refresh
End Sub
 
Upvote 0
Thank you Rick! That worked for that error but now I am getting an run-time error 1004 Unable to get the PivotTables properties of the worksheet class.


You can only have one procedure with any given name in a module... you have the Worksheet_Change event procedure name using three times... that is why you get the Ambiguous Name error... the compiler does not know which one to use. Put all of your code into a single procedure like this...
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Worksheets("Data").PivotTables("PivotTable1").PivotCache.Refresh
  Worksheets("Data").PivotTables("PivotTable2").PivotCache.Refresh
  Worksheets("Data").PivotTables("PivotTable3").PivotCache.Refresh
End Sub
 
Upvote 0
Thank you Rick! That worked for that error but now I am getting an run-time error 1004 Unable to get the PivotTables properties of the worksheet class.
Unfortunately, I am unable to help you with that part of your question as I have no experience using Pivot Tables. Since this is a different question from the one that started this thread, you may want to start a new thread for this particular problem... that way you will expose your new question to the entire volunteer group instead of only those who viewed your original question.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top