+ Reply to Thread
Results 1 to 4 of 4

Look in previous month folder if -2 business day is previosu month

  1. #1
    Registered User
    Join Date
    09-05-2017
    Location
    Hong Kong
    MS-Off Ver
    2013
    Posts
    14

    Look in previous month folder if -2 business day is previosu month

    Hi,

    I have some code that opens a file with different offset of business days depending on the day of the week. At the moment it will always look in the current month folder, 'strYear' in this case.
    I am trying to tweak it so that if the previous file date, 'strFname', falls in the previous month, it searches for it in the previous
    months folder.

    Any ideas and I just can't seem to get it working.

    Please Login or Register  to view this content.

  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: Look in previous month folder if -2 business day is previosu month

    Using the Date - 4 for Mondays and Date - 2 for other days of the week in the Format function should automatically throw it to the previous month if the current day of the monthe is 1 or 2. What exactly is not working for you? Can you give an example of the problem? Maybe all you need is an If statement, ie
    Please Login or Register  to view this content.
    and change your fille path to meet you needs.
    Last edited by JLGWhiz; 04-16-2018 at 04:15 PM.
    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 Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Look in previous month folder if -2 business day is previosu month

    Hello James,

    Here is another way to do it that is more readable...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    09-05-2017
    Location
    Hong Kong
    MS-Off Ver
    2013
    Posts
    14

    Re: Look in previous month folder if -2 business day is previosu month

    Thanks both.

    I used Leith's solution, does the job and tidied up my code. Very much appreciated.

+ 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. VBA code adjustment to include only current month and previous month automatically.
    By ElmerFud in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-05-2015, 03:02 PM
  2. Replies: 1
    Last Post: 07-06-2015, 04:43 PM
  3. Macro using vlookups comparing 2 months paysheet(previous month and current month)
    By srinivasan1965 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-07-2012, 03:45 AM
  4. [SOLVED] VBA to identify the current month and previous month based on system date
    By ravikumar00008 in forum Excel General
    Replies: 10
    Last Post: 07-26-2012, 10:04 AM
  5. Replies: 4
    Last Post: 03-19-2012, 08:58 AM
  6. Re: Previous month's last business day
    By joeljoel in forum Excel General
    Replies: 7
    Last Post: 11-19-2010, 05:53 PM
  7. Previous month's last business day
    By vancoservices in forum Excel General
    Replies: 9
    Last Post: 11-19-2010, 01:43 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