+ Reply to Thread
Results 1 to 5 of 5

Run-time error 13 type mismatch in Excel 2007 VBA when dynamically changing PivotFields

  1. #1
    Registered User
    Join Date
    04-17-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, Excel 2007, Excel 2010
    Posts
    21

    Run-time error 13 type mismatch in Excel 2007 VBA when dynamically changing PivotFields

    Hi All,
    I am stumped. I have what should be a simple VBA script that changes a pivot table based on a user selection (radio button). When user changes selection (from show by % to show by Total) they get the above mentioned error. I have tried changing the datatypes in the underlying SQL table with no luck, and verified that the values are not null. I inherited this with no comments in the rest of the code and could really use some help finding a solution.

    I'm not able to use a string value for DataLabel (i.e. DataLabel = "Sales") for other reasons. I'm sure I am missing something simple.

    Here's where the error shows up (with line 5 highlighted)

    Please Login or Register  to view this content.
    Any and all suggestions are greatly appreciated.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Run-time error 13 type mismatch in Excel 2007 VBA when dynamically changing PivotField

    A bit of a guess, but give this a try.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    04-17-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, Excel 2007, Excel 2010
    Posts
    21

    Re: Run-time error 13 type mismatch in Excel 2007 VBA when dynamically changing PivotField

    Awesome. I can't see why that made a difference, but it fixed my issue! Thank you very much.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Run-time error 13 type mismatch in Excel 2007 VBA when dynamically changing PivotField

    If the DataLabelRange is more than one cell for whatever reason, it throws a Type Mismatch error if you try to assign its values to a string. The .Cell(1,1) qualifies the first cell of the DataLabelRange and circumvents the error.

  5. #5
    Registered User
    Join Date
    04-17-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, Excel 2007, Excel 2010
    Posts
    21

    Re: Run-time error 13 type mismatch in Excel 2007 VBA when dynamically changing PivotField

    Yup. Noticed that. Had to modify it slightly and add a second variable because one of the pivots it creates calculates running totals on two columns (I didn't include that detail in the original post) but I wouldn't have ever thought of your solution on my own.

    The two option buttons ended up looking like this:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Run-Time Type 13 Mismatch Error help - Excel VBA
    By ShakJames in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-08-2015, 06:19 AM
  2. Excel VBA Run-time error '13' Type mismatch
    By svibuk in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-01-2014, 04:23 AM
  3. Excel VBA Run-time error '13' Type mismatch
    By pankajpm in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-27-2013, 05:34 AM
  4. [SOLVED] Excel VBA Run-time error '13' Type mismatch
    By mackypogi in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-17-2013, 02:15 AM
  5. Excel VBA Run-time error '13' Type mismatch
    By edgaryp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-01-2013, 06:48 PM
  6. [SOLVED] VBA Excel 2007 : Autofit Merge Cells Error "Run-time error '13': Type Mismatch"
    By Hudas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-18-2012, 04:10 PM
  7. run-time error 13: type mismatch in VBA (Excel 2007)
    By zeno1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-20-2012, 04:38 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1