Need Macro Help

vxk5018

New Member
Joined
Sep 30, 2014
Messages
9
Hi,

I am fairly proficient at excel but I never seemed to be able to do anything VBA. In one of my spreadsheets, I have a dropdown and when you select a new option in the dropdown, everything in the worksheet automatically updates except for my pivot tables. I need to refresh all every time a new selection is made.

Is it possible to write a macro that "refresh all" whenever a new selection is made in the dropdown? The dropdown is in cell A2.

Thanks for the help!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
This might work.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A2") is Nothing Then
 Application.EnableEvents = False
 ActiveWorkbook.RefreshAll
 Application.EnableEvents = True
End If
End Sub
Copy this code to the worksheet code module for the sheet with the dropdown box. To install the code, right click the sheet name tab, then click 'View Code' in the pop up menu. Copy the code from this thread and paste it into the code pane of the VB Editor. Close the VB editor and save the workbook. The code should now execute any time a change is made in cell A2 of that sheet.
 
Upvote 0
JLGWhiz,

First off, thank you for your help. I appreciate it. I did as you said and when I tried to test it, I got the following error: Compile Error Syntax Error.

Not quite sure what that means. If it helps, the name of the tab is Summary.

Thanks
 
Upvote 0
JLGWhiz,

First off, thank you for your help. I appreciate it. I did as you said and when I tried to test it, I got the following error: Compile Error Syntax Error.

Not quite sure what that means. If it helps, the name of the tab is Summary.

Thanks

It means that I need to pay closer attention to what I am doing. I left a parentheses off. Delete the old one and use this one.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A2")) Is Nothing Then
 Application.EnableEvents = False
 ActiveWorkbook.RefreshAll
 Application.EnableEvents = True
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,986
Members
449,060
Latest member
mtsheetz

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