Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8653911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:39:23+00:00 2026-06-12T14:39:23+00:00

I am getting a mismatch error 13 when running the code below. The whole

  • 0

I am getting a mismatch error 13 when running the code below. The whole code module has been in use and mostly unchanged for over a year, I haven’t changed anything recently, and I am the only user of this workbook.

Non-working code:

Private Sub CreateMIAPivots(MIABook As Workbook, MIASheet As Worksheet, MaxRow As Long)

Dim wksPivotSheet As Worksheet
Dim PivotRange As Range

    Set wksPivotSheet = MIABook.Sheets.Add
    wksPivotSheet.Name = "Summary"
    wksPivotSheet.Tab.Color = RGB(255, 0, 0)

    Set PivotRange = MIASheet.Range("A1:Y" & MaxRow)
    With MIABook.PivotCaches.Add(xlDatabase, PivotRange) 'Error sets here
    'More code below

MaxRow is variable, but I’ve checked it against a file with about 600 to about 7,000 rows, and the Range object is making a valid reference if I try to interact with it any other way.

I have reviewed some related questions here on SO:

  • I am only working in 2003, and the error is different, anyway.
  • I have confirmed I have no other PivotCaches in the workbook before attempting to create a new one.
  • I have successfully gotten this work using the accepted solution here:Use named ranges (see follow-up code below)

Work-around code:

Private Sub CreateMIAPivots(MIABook As Workbook, MIASheet As Worksheet, MaxRow As Long)

Dim wksPivotSheet As Worksheet
Dim pc As PivotCache
Dim lVBAVer As Long
Dim PivotRange As Range

    lVBAVer = CLng(Application.Version)

    Set wksPivotSheet = MIABook.Sheets.Add
    wksPivotSheet.Name = "Summary"
    wksPivotSheet.Tab.Color = RGB(255, 0, 0)

    Set PivotRange = MIASheet.Range("A1:Y" & MaxRow)

    MIABook.Names.Add Name:="PivotRange", RefersTo:=PivotRange

    'Using answer from https://stackoverflow.com/a/11868231/698590 (StackOverflow) 
    'as a guide for version checking. Original answer of 
    'CLng(Application.VBE.Version) did not work here.
    #If lVBAVer <= 11 Then
        Set pc = MIABook.PivotCaches.Add(xlDatabase, "PivotRange")
    #Else
        Set pc = MIABook.PivotCaches.Create(xlDatabase, "PivotRange")
    #End If
    With pc
    'More code below

My question is now why is the above solution necessary? It appears that I am not the only one who has had perfectly working code suddenly stop while using PivotCaches like I had initially. So what is the real root cause here? What caused the code to stop functioning?

I’d like to know so, if possible, I can prevent future unexpected errors from arising. I know that the answer may lie in something I did somewhere else in the code/workbook (not referenced here), but I can’t for the life of me track down what changed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:39:24+00:00Added an answer on June 12, 2026 at 2:39 pm

    So as you already know the problem is related to this: http://answers.microsoft.com/en-us/office/forum/office_2010-customize/pivotcache-type-mismatch-error-when-65536-rows/0827889e-b671-e011-8dfc-68b599b31bf5?msgId=4e3a2b20-7a72-e011-8dfc-68b599b31bf5

    The reason appears to be that the VBA syntax/usage of pivot tables was changed from 2003 to 2007/2010.

    So it uses this common syntax to set a named range in the workbook with this:

    MIABook.Names.Add Name:="PivotRange", RefersTo:=PivotRange
    

    This section of code:

    #If  lVBAVer <= 11 Then 
        Set pc = MIABook.PivotCaches.Add(xlDatabase, "PivotRange") 
    #Else 
        Set pc = MIABook.PivotCaches.Create(xlDatabase, "PivotRange") 
    #End If
    

    Is checking to see if the lVBAver is less than or equal to 11, if is less – then it uses this syntax:

    Set pc = MIABook.PivotCaches.Add(xlDatabase, "PivotRange")
    

    If it is the new version then it uses this syntax:

    Set pc = MIABook.PivotCaches.Create(xlDatabase, "PivotRange") 
    

    Sometimes you just have to accept that Microsoft is not perfect(lol irony) and they do stupid things just like every other company. That is my theory anyways. Good Luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running this code using oozie workflow and getting type mismatch error: public
I am getting a type mismatch error for the below at the if iRowValue
I'm trying to switch my code to use parameters. I'm getting a Type Mismatch
Can someone please explain why I'm getting this error Type mismatch: cannot convert from
Having trouble with the following segment of code. I'm getting a parameter count mismatch.
Getting 'Dispatcher has no subscribers' error while trying to post message to a channel
I am getting a weird error when trying to use a Java map in
I'm getting this error: Data type mismatch in criteria expression when trying to execute
I'm getting a strange type mismatch error in Scala when I try to do
I seem to be getting an error when I use the root-finder in scipy.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.