RunTime error 438 Can anyone see what is wrong with this code?

sheppard26

New Member
Joined
Sep 8, 2009
Messages
20
Hi,

I am trying to set the PivotCache SourceData to a value,which is a filename/path, in a specific cell within the workbook.

I have written the following code but receive a runtime error 438 when running it.

Dim Source As String
Dim PTCache As PivotCache
Source = ActiveWorkbook.Sheets("Macros").Range("B7").Value
Set PTCache = ActiveWorkbook.PivotCaches.create( _
SourceType:=xlDatabase, _
SourceData:=Source)


'Refresh Pivot Cache
Sheets("Spot Sales").PivotTables("Endur Source").PivotCache.Refresh

This Cache is specific to one of many pivottable within the workbook, I have not specified that this cache is relating to this pivottable, could this be the problem? All the other pivot tables are linked to this pivot in question.
I hope this makes sense.


PLEASE PLEASE help, this is driving me nuts!
 
Last edited:
But I thought when using this code when creating the cache it would have a link to the value in cell B7?

Source = ActiveWorkbook.Sheets("Macros").Range("B7").Value

PTCachetest = ActiveWorkbook.PivotCaches.Add( _
SourceType:=xlDatabase, _
SourceData:=Source)

thanks :)
 
Upvote 0

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.
Nope. Source is assigned the value of B7 at the time the code runs and that literal value is then used to build the cache.
 
Upvote 0
ah.... Interesting....

AARGH! Now I have to come up with some ingenious idea to alter this SourceData property as you have said, I am not sure that I am capable of ingenious things!

Thanks for your help so far... I will work on this and prob come back to you...

One more thing, the code that worked perfectly to create cache and pivot etc is now giving me bugs... any idea why it would work perfectly for days and then just conk out, without any changes? VERY FRUSTRATING

Thanks again Rory!
 
Upvote 0
Not without knowing what bugs and on what lines. Could be referring to ranges without specifying sheets, missing field names, or any one of a hundred other things.
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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