+ Reply to Thread
Results 1 to 4 of 4

One Month before xlDateLastMonth

Hybrid View

trizzo One Month before... 05-26-2020, 11:40 AM
6StringJazzer Re: One Month before... 05-26-2020, 04:23 PM
trizzo Re: One Month before... 05-26-2020, 05:15 PM
6StringJazzer Re: One Month before... 05-26-2020, 08:36 PM
  1. #1
    Forum Contributor
    Join Date
    04-02-2012
    Location
    Brazil
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    268

    One Month before xlDateLastMonth

    Hello!

    In the Excel Pivot Table I am able to set the DATE to lastmonth with
     xlDateLastMonth
    , what if I want xlDateLastMonth - 1 (which means one month before xlDateLastMonth)?

    Here is the code which is already working fine. I tried to use xlDateLastMonth - 1 but no success:

     pt.PivotFields("DATE").ClearAllFilters
        pt.PivotFields("DATE").PivotFilters.Add2 _
            Type:=xlDateLastMonth

    The DATE on the pivot table is in this format: 5/1/2020 (m/d/yyyy). So, if I want one month before it should be 4/1/2020 (April)

    Thanks!!
    Last edited by trizzo; 05-26-2020 at 12:28 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,003

    Re: One Month before xlDateLastMonth

    xlDateLastMonth is not the number of the last month. It is a fixed constant that tells Excel to filter the pivot table by whatever was the last month. So you can't do arithmetic on it. You need to calculate the month and use xlDateBetween.

    pt.PivotFields("DATE").PivotFilters. _
       Add Type:=xlDateBetween, Value1:=DateSerial(Year(Date),Month(Date)-2,1), Value2:=DateSerial(Year(Date),Month(Date)-1,1)-1
    I have not tested this. Feel free to attach your file for further help if this does not work.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    04-02-2012
    Location
    Brazil
    MS-Off Ver
    Excel 2007 & 2013
    Posts
    268

    Re: One Month before xlDateLastMonth

    This is just great! Thanks a lot!!!

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,003

    Re: One Month before xlDateLastMonth

    You're welcome and thanks for the rep!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Caclulate month of quarter (1st month - 3rd month)
    By kuraitori in forum Excel General
    Replies: 5
    Last Post: 07-15-2018, 03:53 PM
  2. [SOLVED] Calculation of days per month for dates beginning in one month and ending in another month
    By Fahrettin in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-07-2015, 04:52 PM
  3. [SOLVED] Determine work days in current month or next month based on day of the month
    By sbrnard in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 05-29-2014, 05:14 PM
  4. [SOLVED] Counting & summing formula (until last month,this month,until this month..
    By Jhon Mustofa in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-12-2014, 01:14 PM
  5. [SOLVED] Auto instert Month names for This month, Last month and Next month
    By hemal89 in forum Word Programming / VBA / Macros
    Replies: 4
    Last Post: 12-10-2013, 12:01 PM
  6. Changing number of days in a month based on month chosen from a dropdown list.
    By st_judeu@yahoo.com in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-08-2013, 02:26 PM
  7. [SOLVED] display cell to show only Month/year to do sumif calc if today()= any day of month
    By fireguy7 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-12-2013, 06:55 PM

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