+ Reply to Thread
Results 1 to 5 of 5

Please help! Macro with dynamic range and pivot table Excel 2010

  1. #1
    Registered User
    Join Date
    04-18-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    5

    Please help! Macro with dynamic range and pivot table Excel 2010

    Hello.

    I'm rather new to doing macros. I have a little programming experience from college. I have a speadsheet that I'm trying to create a macro for that needs a dynamic range. My header line is on Row 5. Currently when I run my code it appears that I'm getting an extra row at the bottom that is all blank so when I view my pivot table I end up with a blank fiscal year column and blank fiscal qtr rows. Because of this I believe it is causing my second issue where I cannot group by month on the invoice date section.

    I've been working on this for a couple of days and I'm very frustrated. I appreciate any help you can provide.

    Code section:
    ActiveWorkbook.Names.Add Name:="PvtData", RefersToR1C1:= _
    "=OFFSET('Sell thru Invoice Detail for Ma'!R5C1,0,0,COUNTA('Sell thru Invoice Detail for Ma'!C1),COUNTA('Sell thru Invoice Detail for Ma'!R5))"



    Sheets.Add
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "PvtData", Version:= _
    xlPivotTableVersion10).CreatePivotTable TableDestination:="Sheet1!R3C1", _
    TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
    Sheets("Sheet1").Select
    Cells(3, 1).Select
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Fiscal year")
    .Orientation = xlColumnField
    .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Fiscal qtr")
    .Orientation = xlRowField
    .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
    "PivotTable1").PivotFields("Extended Cost"), "Sum of Extended Cost", xlSum
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Invoice " & Chr(10) & "Date")
    .Orientation = xlRowField
    .Position = 2
    End With

    Range("B4").Select
    Selection.Group Start:=True, End:=True, Periods:=Array(False, False, False, _
    False, True, False, False)
    Last edited by sassylogo; 04-22-2013 at 09:43 AM.

  2. #2
    Registered User
    Join Date
    04-18-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro with dynamic range and pivot table Excel 2010

    Is anyone able to help with this?

    Thanks

  3. #3
    Registered User
    Join Date
    04-18-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro with dynamic range and pivot table Excel 2010

    bumpity bump

  4. #4
    Registered User
    Join Date
    04-18-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Please help! Macro with dynamic range and pivot table Excel 2010

    Based on a recommendation I added:

    ActiveSheet.PivotTables("PivotTable1").PivotFields("Fiscal year").PivotItems("(blank)").Visible = False

    prior to the grouping. That removed the "blanks" in the pivot table, however it is still crashing on the grouping stating "cannot group selection".

    Any suggestions are welcome.
    thanks

  5. #5
    Valued Forum Contributor
    Join Date
    08-13-2012
    Location
    Gardony, Hungary
    MS-Off Ver
    Excel 2003
    Posts
    558

    Re: Please help! Macro with dynamic range and pivot table Excel 2010

    Can you upload a sample file that includes data and the code as well? Might be able to help then.

  6. #6
    Registered User
    Join Date
    04-18-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Please help! Macro with dynamic range and pivot table Excel 2010

    I got this figured out.

+ 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