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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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