+ Reply to Thread
Results 1 to 2 of 2

VBA Error - Pivot Table

  1. #1
    Registered User
    Join Date
    12-18-2015
    Location
    NZ
    MS-Off Ver
    2003
    Posts
    1

    VBA Error - Pivot Table

    Hi

    I am trying to generate a pivot table but I keep getting a "type mismatch" error. Code I use is:

    Worksheets("O").Activate
    Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Set myRng = Selection

    Worksheets("Generate").Activate

    Set tableRange = Range(ActiveCell, ActiveCell.Offset(0, 0))
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, _
    SourceData:=myRng, Version:=xlPivotTableVersion12).CreatePivotTable _
    TableDestination:=tableRange, TableName:="PivotTable4", DefaultVersion _
    :=xlPivotTableVersion12


    I have noticed that changing "SourceData:=myRng" to actual range (e.g. SourceData:="O!A1:R1000" works. However, I have been able to generate the pivot table successfully with the above code for several other files. I can't figure out why this one is generating an error.
    Last edited by mehc011; 12-18-2015 at 09:15 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,005

    Re: VBA Error - Pivot Table

    Welcome to the forum.

    Try changing it to myRng.Address


    Regards, TMS



    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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. [SOLVED] Need error handler code to avoid pivot table refreshing error if no data is available
    By adelkam in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-04-2015, 12:37 PM
  2. Error with pivot items in pivot table
    By cool1_boy1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2015, 10:57 AM
  3. VBA: Pivot Tables / Error 1004: Pivot Table Not Valid
    By vidyuthrajesh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-22-2013, 03:54 PM
  4. [SOLVED] VBA Pivot table error
    By amotto11 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-22-2013, 01:05 PM
  5. Pivot table error message but can't find the offending pivot table
    By dcoates in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 01-22-2013, 08:45 AM
  6. Pivot table and Pivot Chart - Run time error 5
    By yogananda.muthaiah in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-30-2012, 08:35 AM
  7. Replies: 3
    Last Post: 03-26-2008, 07:34 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