Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 493
  • Last Modified:

vba macro for pivot table including "blank"

I am running the attached vba for creating a pivot table from the attached data. I don't know why it is including "blank" as one of the entries in the pivot table.
Sub makeRelativePivot2()
'
' makeRelativePivot2 Macro
'

'
  
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "perStockTweets!R1C1:R3926C7", Version:=xlPivotTableVersion14). _
        CreatePivotTable TableDestination:="", TableName:="PivotTable5" _
        , DefaultVersion:=xlPivotTableVersion14

    With ActiveSheet.PivotTables("PivotTable5").PivotFields("Date")
        .Orientation = xlRowField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable5").AddDataField ActiveSheet.PivotTables( _
        "PivotTable5").PivotFields("Tweet ID"), "Sum of Tweet ID", xlSum
    ActiveCell.Offset(0, 1).Range("A1").Select
    ActiveSheet.PivotTables("PivotTable5").PivotFields("Sum of Tweet ID").Function _
        = xlCount
End Sub

Open in new window

Anyone know about it?
0
willie108
Asked:
willie108
  • 4
  • 2
1 Solution
 
Rory ArchibaldCommented:
Hard to be sure without the data but I'd guess one of your key cells is blank.
0
 
willie108Author Commented:
Hello. I thought I attached the data. Let me try it again.
sample.csv
0
 
willie108Author Commented:
Hello. I attached the data in the previous post. I also tried to make a pivot table manually and did not get a blank row.
Thanks.
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!

 
Rory ArchibaldCommented:
Your code uses A1:G3926 as the source data but you only have data to row 1602. That's why you get Blank in the macro created pivot table.
Change this:
   ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "perStockTweets!R1C1:R3926C7", Version:=xlPivotTableVersion14). _
        CreatePivotTable TableDestination:="", TableName:="PivotTable5" _
        , DefaultVersion:=xlPivotTableVersion14

Open in new window


to this:
   ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "perStockTweets!" & sheets("perStockTweets").range("A1").Currentregion.address(referencestyle:=xlr1c1), Version:=xlPivotTableVersion14). _
        CreatePivotTable TableDestination:="", TableName:="PivotTable5" _
        , DefaultVersion:=xlPivotTableVersion14

Open in new window

0
 
willie108Author Commented:
Thanks. Will that be flexible? I want to use it on data for which I don't know the number of rows.
0
 
willie108Author Commented:
Great. Thanks.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now