+ Reply to Thread
Results 1 to 2 of 2

Problem with a pivot table in my macro

  1. #1
    Forum Contributor
    Join Date
    10-28-2003
    Location
    Happyville, USA
    MS-Off Ver
    365
    Posts
    300

    Problem with a pivot table in my macro

    Hi,

    I'm working on a macro. One of the things it has to do is create a pivot table. It works but I can't promise that range will always be 9505. It may be more lines or less in the future. How do I change the code so it will pick up all the data on sheet regardless of how many lines there are? Column AF will always have data in it so maybe there is a way to tell it to take everything down through the last cell with data in that column.

    Any thoughts?

    Thanks

    Eddie

    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
    "'Corp Paying'!R1C1:R9505C32").CreatePivotTable TableDestination:="", _
    TableName:="PivotTable4", DefaultVersion:=xlPivotTableVersion10
    ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
    ActiveSheet.Cells(3, 1).Select
    With ActiveSheet.PivotTables("PivotTable4")
    .ColumnGrand = False
    .RowGrand = False
    End With
    ActiveSheet.PivotTables("PivotTable4").AddFields RowFields:="Shipper_Company" _
    , ColumnFields:="GL Code"
    ActiveSheet.PivotTables("PivotTable4").PivotFields("AmtDue").Orientation = _
    xlDataField
    ActiveWorkbook.ShowPivotTableFieldList = False

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    This site might help with your range problem

    http://www.contextures.com/xlPivot01.html

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1