Run Time Error 13 type Mismatch in Pivot table

Manivannangnnavel94

New Member
Joined
Jan 23, 2020
Messages
4
Office Version
  1. 2010
Platform
  1. Windows
Hi,

I have created a Pivot Create Code which worked Correctly. But Now the Data i am trying to use the code is of high columns and rows.

Is there any solution on correcting this code.

which must work in larger data too.
VBA Code:
Sub EGPivotCreate(DataSourceSheetName As String, DataSourceAddress As String, _
    DestinationSheetName As String, DestinationAddress As String, PivotName As String)
 
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    Worksheets(DataSourceSheetName).Range(DataSourceAddress)). _
    CreatePivotTable TableDestination:=Worksheets(DestinationSheetName).Range(DestinationAddress), _
    TableName:=PivotName

End Sub
 

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.
Use the address strings instead of a range:

Code:
 ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="'" & _
    DataSourceSheetName & "'!" & .Range(DataSourceAddress).Address(referencestyle:=xlR1C1))

If you can, or already do, pass the address in R1C1 format, you can use the address string directly.
 
Upvote 0
Hi rory,

I have been using as Variable like A1 Style Address, Since the Address Varies each time the product Changes. So How is it Possible to use the R1C1 format?

Use the address strings instead of a range:

Code:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="'" & _
    DataSourceSheetName & "'!" & .Range(DataSourceAddress).Address(referencestyle:=xlR1C1))

If you can, or already do, pass the address in R1C1 format, you can use the address string directly.
 
Upvote 0
The code I posted will convert from A1 style to R1C1 style for you. I don't know how you are getting the initial address string at the moment, so I can't suggest how to alter that earlier.
 
Upvote 0
The code I posted will convert from A1 style to R1C1 style for you. I don't know how you are getting the initial address string at the moment, so I can't suggest how to alter that earlier.


I am adding an Initial address from my data sheet which Selects the address and the Address expressed a Variable and Inserted in the EGPivot Create

Example:
Call EGPivotCreate("Provision Vs actuals", Pivotaddress, Provvsactpivot, "a1", "pvapivot")

Provision Vs Actuals - DataSourceSheetName

Pivotaddress(Defined as variable) - DataSourceAddress

Provvsactpivot(defined as a variable) - DestinationSheetName

"A1"- DestinationAddress

pvapivot -PivotName


the datasource varies since each time according to the criteria provided.
This Alone need a solution.

I tried the code which you have provided above but it the code is not even moving down to the pivot codes i have provided in the VBE.

Kindly Suggest me any other option.
 
Upvote 0
Hi Rory,

Thanks for the suggestion i made some modification with the suggestion previously provided. Modified


VBA Code:
        ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="'" & _
    DataSourceSheetName & "'!" & Range(DataSourceAddress).Address(ReferenceStyle:=xlR1C1)

Now its Working Dynamically.

:)
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

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