Results 1 to 4 of 4

Pivot Table Script Change

Threaded View

  1. #1
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Pivot Table Script Change

    I have this pivot table script that was working fine in another workbook.

    But then I needed it to run only on the last sheet of another workbook. So I took out "For each ws in worksheets" now I am getting an error "object variable or with block not set"

    Not sure what happend?

    Any Idea's?

    Here is the code, Thanks for helping, Mike

    Sub Pivot2()
    
        Dim Ws As Worksheet, strSource As String
        Dim PT As PivotTable, pc As PivotCache, pf As PivotField
        
         With ActiveWorkbook.Worksheets(Sheets.Count)
           
            
                'For Each Ws In ActiveWorkbook.Worksheets
             ActiveWorkbook.ShowPivotTableFieldList = False
             Application.CommandBars("PivotTable").Visible = False
             Application.DisplayAlerts = False
             Application.ScreenUpdating = False
    
    
            strSource = Ws.Name & "!R1C1:R5000C4"
            ActiveWorkbook.Worksheets.Add      'new worksheet becomes the active sheet
            'ActiveSheet.Name = "Info"
            
            Set pc = ActiveWorkbook.PivotCaches.Add(xlDatabase, strSource)
            Set PT = pc.CreatePivotTable(Range("A1"))   'pivot table at A1 on new sheet
            
            Set pf = PT.PivotFields("Order Number")
    
            PT.AddDataField pf, "Count of Order Number", xlCount
            PT.AddFields RowFields:="Name"
            Application.DisplayAlerts = True
            Application.ScreenUpdating = True
                    'Next Ws
        
         End With
              
    End Sub
    Last edited by realniceguy5000; 12-18-2008 at 12:05 PM.

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