+ Reply to Thread
Results 1 to 7 of 7

Change VBA code to report last month i.e. May as opposed to this month i.e. June in file n

  1. #1
    Forum Contributor
    Join Date
    02-09-2004
    Location
    Cardiff - Wales - UK
    MS-Off Ver
    2013
    Posts
    475

    Question Change VBA code to report last month i.e. May as opposed to this month i.e. June in file n

    Hi,

    Can anyone please advise me of the syntax I need to amend the following VBA/macro code.

    The code current does exactly what it is supposed to do i.e. save the file in the current path of the file, and save it as ‘Monthly Projects Within Schedule Report (June 2018)’.xlsx', however, as the report’s data is for the previous month, I need the code to be amended so it doesn’t report the current month but the previous month e..g ‘Monthly Projects Within Schedule Report (May 2018)’.xlsx',

    Please Login or Register  to view this content.
    ActiveWorkbook.SaveAs Filename:=srcWB.Path & "\Monthly Projects Within Schedule Report (" & Format(Date, "MMMM-yyyy") & ").xlsx", FileFormat:=51
    Please Login or Register  to view this content.
    Any assistance in this matter would be greatly appreciated

    Many thanks in advance

    Regards


    Rob
    Rob

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Change VBA code to report last month i.e. May as opposed to this month i.e. June in fi

    Please Login or Register  to view this content.
    subtract 28 days from the current date as shown above.
    Last edited by JLGWhiz; 06-04-2018 at 10:33 AM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Contributor
    Join Date
    02-09-2004
    Location
    Cardiff - Wales - UK
    MS-Off Ver
    2013
    Posts
    475

    Re: Change VBA code to report last month i.e. May as opposed to this month i.e. June in fi

    JLGWhiz

    EXCELLENT !!

    Many thanks for your assistance


    Thanks Again


    Regards


    Rob

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,552

    Re: Change VBA code to report last month i.e. May as opposed to this month i.e. June in fi

    Are you sure about subtracting 28 days?

    If the date is 31 st of May, it still May, so should be
    Please Login or Register  to view this content.

  5. #5
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Change VBA code to report last month i.e. May as opposed to this month i.e. June in fi

    Quote Originally Posted by jindon View Post
    Are you sure about subtracting 28 days?

    If the date is 31 st of May, it still May, so should be
    Please Login or Register  to view this content.
    If you subtract more than 28 days it could put March 1st back into January. It was assumed that the report will be initiated sometime within the first week of the new month. Any later would have people working from old data which could be obsolete and misleading. But your suggestion would work well for most months.
    Last edited by JLGWhiz; 06-06-2018 at 09:55 AM.

  6. #6
    Registered User
    Join Date
    07-02-2018
    Location
    USA, CA, San Jose
    MS-Off Ver
    2010
    Posts
    2

    Re: Change VBA code to report last month i.e. May as opposed to this month i.e. June in fi

    many thanks for the answers i found here as it is super helpful for me. was wondering if i may ask questions in case i would have some? i'm just a newbie so i don't know... thanks

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,552

    Re: Change VBA code to report last month i.e. May as opposed to this month i.e. June in fi

    Swithim,

    Yes you can, but not in this thread.
    You need to open a new thread for your own question.

+ 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. Submit data at end of month so the values do not change when new month starts
    By jamesraywebber in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-10-2018, 02:51 PM
  2. Change Pivot Table Fields Month by Month Automatically
    By phoebeyanan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-16-2017, 04:03 PM
  3. Replies: 3
    Last Post: 07-16-2014, 02:53 PM
  4. [SOLVED] Using VBA to return Month and Year from B306 which is June 2013
    By sdeaks in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-25-2014, 10:26 AM
  5. Replies: 4
    Last Post: 09-09-2013, 05:06 AM
  6. How to change a report's data based on the month
    By stacycmc in forum Excel General
    Replies: 0
    Last Post: 07-22-2009, 03:27 PM
  7. [SOLVED] Automatically save report to new file name each month
    By mhayli in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-03-2005, 10:05 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