+ Reply to Thread
Results 1 to 9 of 9

amend code to exclude weekends

  1. #1
    Forum Contributor
    Join Date
    05-30-2015
    Location
    Dubai
    MS-Off Ver
    Excel 2016 Mac & PC & 365
    Posts
    633

    amend code to exclude weekends

    Hi,

    I am using the following code which was very kindly provided from this site.
    I would like to amend it to exclude weekends (Saturday & Sunday) as I have now removed these dates from my sheet

    Please Login or Register  to view this content.
    Thanks
    Kevin

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: amend code to exclude weekends

    How about this.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Forum Contributor
    Join Date
    05-30-2015
    Location
    Dubai
    MS-Off Ver
    Excel 2016 Mac & PC & 365
    Posts
    633

    Re: amend code to exclude weekends

    Thank you for looking......It dosent appear to be working?
    I have simply replaced the entire code with the code suggested, is that correct

    I get no error message either

  4. #4
    Forum Contributor
    Join Date
    05-30-2015
    Location
    Dubai
    MS-Off Ver
    Excel 2016 Mac & PC & 365
    Posts
    633

    Re: amend code to exclude weekends

    I think the issue may be that
    Please Login or Register  to view this content.
    is greater the 5, then what?
    Last edited by Excelski; 12-09-2018 at 07:08 AM. Reason: Just guessing!!

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: amend code to exclude weekends

    Weekday returns the daynumber in a week of a certain date. Monday = 1 to Friday = 5.
    The function Weekday is now instructed to start on Monday so if Date - 1 returns 6 or 7 means it's a weekend day.
    In that case we have to do nothing.

  6. #6
    Forum Contributor
    Join Date
    05-30-2015
    Location
    Dubai
    MS-Off Ver
    Excel 2016 Mac & PC & 365
    Posts
    633

    Re: amend code to exclude weekends

    Okay, thanks. Thinking about it a bit more this scenario will only occur when the sheet is opened on a Monday, so instead of doing nothing can go to Monday instead?

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: amend code to exclude weekends

    How about this then.
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    05-30-2015
    Location
    Dubai
    MS-Off Ver
    Excel 2016 Mac & PC & 365
    Posts
    633

    Re: amend code to exclude weekends

    Great...works perfectly, thanks!
    Kevin

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: amend code to exclude weekends

    Glad to help and thanks for 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. Amend VBA Range to exclude header row
    By robertguy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2018, 08:03 AM
  2. Amend VBA Range to exclude header row
    By robertguy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-17-2018, 05:43 AM
  3. Exclude weekends in chart
    By gnoke in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-18-2010, 08:03 AM
  4. Cannot Exclude weekends from XValues
    By wildjester in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 08-10-2009, 01:25 PM
  5. How do I set up a calculation to exclude weekends?
    By Ken Proj mgr in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-08-2006, 10:55 AM
  6. calculation to exclude weekends
    By Bob Phillips in forum Excel Formulas & Functions
    Replies: 20
    Last Post: 09-06-2005, 03:05 PM
  7. calculation to exclude weekends
    By Need2Know in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM

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