+ Reply to Thread
Results 1 to 3 of 3

Formattting the date in a Pivot Chart

Hybrid View

hattrick_123a Formattting the date in a... 11-16-2011, 12:01 AM
Miraun Re: Formattting the date in a... 11-16-2011, 01:07 AM
hattrick_123a Re: Formattting the date in a... 11-16-2011, 04:08 PM
  1. #1
    Registered User
    Join Date
    04-28-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2003
    Posts
    24

    Question Formattting the date in a Pivot Chart

    Hi There

    Appreciate any help with this.

    I have a pivot chart with the following date format:
    6/11/2011

    Now I want to change it into the following date format:
    6/11/2011 0:00

    To do this I get the following Macro after recording it

    Sub Macro4()
    '
    ' Macro4 Macro
    '
    '
        Range("A2").Select
        ActiveSheet.PivotTables("PivotTable2").PivotFields("Time").Name = _
            "d/mm/yyyy h:mm"
    End Sub

    But if I run this Macro(Macro4) it changes the PivotField “Time” to “d/mm/yyyy h:mm “, which is not what I want.

    Can anyone please help me correct this?? See attached.




    Building from this I have multiple sheets with Pivot Charts with the date format:

    6/11/2011

    I have created the following Macro that will go through every Pivot Chart in every Pivot Sheet and hopefully change it to the format I want:
    6/11/2011 0:00

    The Macro is below, but it is not doing what I want it to do. As I have copied the line from the recorded macro above.

    Sub generic()
    '' this goes through every worksheet
    
    
    Dim ws As Worksheet
    Dim objPT As PivotTable
    Dim objPTField As PivotField
    Dim objPTItem As PivotItem
    
    For Each ws In Worksheets
    ws.Visible = xlSheetVisible
    MsgBox "WorkSheet: " & ws.Name & vbCrLf
        
        
        Range("A2").Select
               For Each objPT In ws.PivotTables
            MsgBox "PivotTable: " & objPT.Name & vbCrLf
             For Each objPTField In objPT.PivotFields
                         
    objPT.PivotFields("Time").Name = _
            "d/mm/yyyy h:mm"
    
                Next
            Next objPT
    Next ws
    
    End Sub

    So I think if I get this line of code right I will be all set.

    objPT.PivotFields("Time").Name = _
            "d/mm/yyyy h:mm"
    Thanks

  2. #2
    Valued Forum Contributor Miraun's Avatar
    Join Date
    04-03-2009
    Location
    New England
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    554

    Re: Formattting the date in a Pivot Chart

    SO CLOSE!

        ActiveSheet.PivotTables("PivotTable2").PivotFields("Time").NumberFormat = "d/mm/yyyy h:mm"
    Going for Guru! Click the Star to the bottom left of this post if I helped!

  3. #3
    Registered User
    Join Date
    04-28-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Formattting the date in a Pivot Chart

    Hey Miraun

    Thanks for that. Just trying to understand why the macro did not record it the way you wrote it?

    Also, is there a good place to find the various properties options available to this object(e.g. Pivot Field.NumberFormat)?? I mean should I be able to find this somewhere or does this come with experience?

    Thanks Again
    Last edited by hattrick_123a; 11-16-2011 at 04:10 PM. Reason: correction

+ 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