Refresh data in Pivot table!

Milksnatcher

New Member
Joined
Sep 21, 2009
Messages
7
Hi, I am a complete VBA newcomer and I have a worksheet in which I want to refresh the data in a pivot table. The data is kept in several identical worksheets. I recorded a macro to change te data which worked fine.... but I wat to be able to change the spreadsheet name by a string name:

Sub Macro4()
'

sheet = Worksheets("Results").Range("b4")

Range("B8").Select

ActiveSheet.PivotTableWizard SourceType:=xlDatabase, SourceData:= _
"sheet!R1C2:R242C4"
End Sub

I have a validation list in Results!B4, which contains the names of all the sheets. No matter how I have tried to reference the data path I keep on getting it wrong. Can someone help me? The range of data will be the same, but the sheet name needs to change according to the validation list selection. I'm stumped.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Welcome to the Board.

I don't see any refreshing there. That code is creating a pivot table. You can set the SourceData like this:

Code:
ActiveSheet.PivotTableWizard SourceType:=xlDatabase, SourceData:= _
"'" & sheet & "'!R1C2:R242C4"
 
Upvote 0
Hi, this was a macro that I recorded by going to the wizard and then changing the sourcedata. Can you let me know how to refresh it correctly?
 
Upvote 0
You are a star, thank you so much, I have wasted so much time trying to get this to work. You may end up with more posts as the project gets progressively more complex!
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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