+ Reply to Thread
Results 1 to 2 of 2

run-time error '9': Subscript out of range

  1. #1
    Registered User
    Join Date
    03-07-2006
    Posts
    19

    run-time error '9': Subscript out of range

    Can anyone tell me why i get this error?

    Sub ChangePivotCache()
    'change pivot cache for all pivot tables in workbook
    Dim pt As PivotTable
    Dim wks As Worksheet

    For Each wks In ActiveWorkbook.Worksheets
    For Each pt In wks.PivotTables
    pt.CacheIndex = Sheets("Pivot").PivotTables(1).CacheIndex
    Next pt
    Next wks

    End Sub

    PLEASE HELP!!

  2. #2
    Chip Pearson
    Guest

    Re: run-time error '9': Subscript out of range

    What line is giving you the error? Most likely it is
    pt.CacheIndex = Sheets("Pivot").PivotTables(1).CacheIndex

    Are you sure you have a sheet call "Pivot" and are you sure that
    there is at least one pivot table on it?


    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com


    "jerredjohnson"
    <jerredjohnson.24d6xn_1141844102.6615@excelforum-nospam.com>
    wrote in message
    news:jerredjohnson.24d6xn_1141844102.6615@excelforum-nospam.com...
    >
    > Can anyone tell me why i get this error?
    >
    > Sub ChangePivotCache()
    > 'change pivot cache for all pivot tables in workbook
    > Dim pt As PivotTable
    > Dim wks As Worksheet
    >
    > For Each wks In ActiveWorkbook.Worksheets
    > For Each pt In wks.PivotTables
    > pt.CacheIndex = Sheets("Pivot").PivotTables(1).CacheIndex
    > Next pt
    > Next wks
    >
    > End Sub
    >
    > PLEASE HELP!!
    >
    >
    > --
    > jerredjohnson
    > ------------------------------------------------------------------------
    > jerredjohnson's Profile:
    > http://www.excelforum.com/member.php...o&userid=32236
    > View this thread:
    > http://www.excelforum.com/showthread...hreadid=520228
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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