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!
 

Some videos you may like

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
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.
 

vxk5018

New Member
Joined
Sep 30, 2014
Messages
9
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
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
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
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
You're welcome,
Regards, JLG
 

Watch MrExcel Video

Forum statistics

Threads
1,122,469
Messages
5,596,329
Members
414,055
Latest member
mcarduner

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
Top