[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Pivot not working.

Posted on 2013-12-27
8
Medium Priority
?
372 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 

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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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 will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

650 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