Solved

Pivot not working.

Posted on 2013-12-27
8
369 Views
Last Modified: 2013-12-28
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
0
Comment
Question by:RWayneH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 40

Expert Comment

by:als315
ID: 39742359
Try to change
Sheets.Add
to
Sheets.Add.Name = "Sheet5"
0
 

Author Comment

by:RWayneH
ID: 39742384
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-
0
 
LVL 40

Expert Comment

by:als315
ID: 39742420
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?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:RWayneH
ID: 39742472
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
0
 
LVL 40

Expert Comment

by:als315
ID: 39742544
Can you show expected result?
0
 

Author Comment

by:RWayneH
ID: 39742565
0
 
LVL 40

Accepted Solution

by:
als315 earned 500 total points
ID: 39743226
Macro recorder very often skip some steps, so you should add them manually.
You can find guide here:
http://msdn.microsoft.com/en-us/library/hh243933(v=office.14).aspx
This code should work:
Sub Pivot1()
Dim objTable As Object
    Sheets("Open Orders").Activate
    Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Name = "SOSOLNRange"
    Sheets.Add.Name = "Sheet5"
    Sheets("Sheet5").Activate
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "SOSOLNRange", Version:=xlPivotTableVersion12).CreatePivotTable TableDestination:="Sheet5!R3C1", TableName:="PivotTable8" _
        , DefaultVersion:=xlPivotTableVersion12
    Set objTable = ActiveSheet.PivotTables("PivotTable8")
    Set objField = objTable.PivotFields("SOSOLN")
    objField.Orientation = xlRowField
    Set objField = objTable.PivotFields("SOSOLN")
    objField.Orientation = xlDataField
    objField.Function = xlCount
End Sub

Open in new window

0
 

Author Closing Comment

by:RWayneH
ID: 39743378
EXCELlent!!  Thanks. -R-
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question