Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50190

Macro failing when Sheet1 was previously created and new sheets are Sheets2+

$
0
0
How do I modify that where the macro adds the sheet and then uses that sheet and completely disregards sheet names?


Code:

Attribute VB_Name = "Mailroom"
Option Explicit


Sub Mailroom()
'
' Macro1 Macro
'

'
Sheets("Original Data").Select
    Range("A1").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$K$18618").AutoFilter Field:=1, Criteria1:=Array( _
        "jp"), Operator:=xlFilterValues
    ActiveSheet.Range("$A$1:$K$18618").AutoFilter Field:=4, Criteria1:= _
        "User Completed Work"
    Range("E:E,F:F,H:H,I:I,J:J,K:K").Select
    Selection.Delete Shift:=xlToLeft
    Columns("A:E").Select
    Selection.Copy
    Sheets.Add After:=ActiveSheet
    ActiveSheet.Paste
    Columns("C:C").EntireColumn.AutoFit
    Application.CutCopyMode = False
    Sheets.Add
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Sheet1!R1C1:R1030209C5", Version:=6).CreatePivotTable TableDestination:= _
        "Sheet2!R3C1", TableName:="PivotTable1", DefaultVersion:=6
    Sheets("Sheet2").Select
    Cells(3, 1).Select
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Agency User ID")
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Exit Result")
        .Orientation = xlRowField
        .Position = 2
    End With
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
        "PivotTable1").PivotFields("Packet ID"), "Count of Packet ID", xlCount

End Sub


Viewing all articles
Browse latest Browse all 50190

Trending Articles