+ Reply to Thread
Results 1 to 2 of 2

Repeat a Pivot Macro on Specific Worksheets

  1. #1
    Registered User
    Join Date
    04-15-2014
    Location
    Melbourne
    MS-Off Ver
    Excel 2010
    Posts
    1

    Repeat a Pivot Macro on Specific Worksheets

    Hi there,

    I need help with repeating this macro to create a pivot table on all but two worksheets in my workbook. What I have developed here works perfectly for creating the pivot table on the one sheet. Whenever I try looping it by excluding a few sheets I run into issues. Many thanks in advance for your help. The two worksheets that need to be excluded are titled "Dashboard" and "Downtime Report"

    Sub CreatePivot()

    Dim shtSource As Worksheet
    Dim rngSource As Range, rngDest As Range
    Dim pvt As PivotTable


    Set shtSource = ActiveSheet
    Set rngSource = shtSource.Range("A1").CurrentRegion
    Set rngDest = ActiveSheet.Range("J9")

    Set pvt = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=rngSource, _
    Version:=xlPivotTableVersion12).CreatePivotTable _
    (TableDestination:=rngDest, DefaultVersion:=xlPivotTableVersion12)

    pvt.AddDataField pvt.PivotFields("date"), "Count of date", xlCount

    With pvt.PivotFields("date")
    .Orientation = xlRowField
    .Position = 1
    End With

    With pvt.PivotFields("ex/inc")
    .Orientation = xlPageField
    .Position = 1
    End With

    With pvt.PivotFields("up/down")
    .Orientation = xlPageField
    .Position = 1
    End With

    pvt.PivotFields("ex/inc").ClearAllFilters
    pvt.PivotFields("ex/inc").CurrentPage = _
    "included"
    pvt.PivotFields("up/down").ClearAllFilters
    pvt.PivotFields("up/down").CurrentPage = _
    "DOWN"

    End Sub

  2. #2
    Valued Forum Contributor Hawkeye16's Avatar
    Join Date
    02-27-2013
    Location
    Holland
    MS-Off Ver
    ├•┤ Pew Pew
    Posts
    441

    Re: Repeat a Pivot Macro on Specific Worksheets

    Please use code tags when posting code. It would be nice to see what you tried that did not work as well. I believe you would use something like this though. (untested)


    edit: This is a little redundant with the worksheet variables, you could get rid of one of them.
    Please Login or Register  to view this content.
    Despite the high cost of living, it remains very popular.

    Don't forget to mark threads SOLVED when you get an answer and rep all the geniouses that helped you today!

+ 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. Need to repeat macro across multiple worksheets in workbook
    By iasiddiqui77 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-13-2014, 03:15 PM
  2. [SOLVED] Need Macro to repeat row specific number of times
    By KimberlyS in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-23-2014, 06:12 PM
  3. [SOLVED] Macro - Repeat macro a specific number of times
    By uvinduds in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-25-2013, 02:42 PM
  4. macro to repeat all rows cell acording to specific value
    By sherif in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-05-2012, 11:13 AM
  5. [SOLVED] macro to repeat all rows cell acording to specific value
    By ispyhope in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-05-2012, 08:22 AM

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