Avatar of RWayneH
RWayneH
Flag for United States of America asked on

Pivot not working.

For some reason this Pivot is not working.  Any ideas why this would not preform the way it was recorded?  It should create a sheet tab "Sheet5" everytime and it is not.  There are four other sheet tabs in this file.  Thanks  -R-


Sub Pivot1()

    Columns("A:A").Select
    Sheets.Add
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Open Orders!R1C1:R1048576C1", Version:=xlPivotTableVersion12). _
        CreatePivotTable TableDestination:="Sheet5!R3C1", TableName:="PivotTable8" _
        , DefaultVersion:=xlPivotTableVersion12
    Sheets("Sheet5").Select
    Cells(3, 1).Select
    With ActiveSheet.PivotTables("PivotTable8").PivotFields("SOSOLN")
        .Orientation = xlRowField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable8").AddDataField ActiveSheet.PivotTables( _
        "PivotTable8").PivotFields("SOSOLN"), "Count of SOSOLN", xlCount

Open in new window

Pivot1.xlsx
Microsoft ApplicationsMicrosoft OfficeMicrosoft Excel

Avatar of undefined
Last Comment
RWayneH

8/22/2022 - Mon
als315

Try to change
Sheets.Add
to
Sheets.Add.Name = "Sheet5"
RWayneH

ASKER
No luck... it creates the sheet tab fine... it however does not put the SOSOLN in the rows of the pivot table, only in the column as a Count... -R-
als315

Your question was:
It should create a sheet tab "Sheet5" everytime and it is not.
Do you like to get on inserted sheet pivot table from sheet6 in your sample?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
RWayneH

ASKER
If I create the workbook in sequence it does create Sheet5, even with your edit... however look at what the pivot looks like.... it does not honor the SOSOLN into the rows... as the recorder does it.  Something is going on in the using of the same field as rows and values..

Please run the code and you will see what I mean.  (at least is has not been  working for me).
PivotError.jpg
als315

Can you show expected result?
RWayneH

ASKER
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
als315

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
RWayneH

ASKER
EXCELlent!!  Thanks. -R-