+ Reply to Thread
Results 1 to 12 of 12

How to use Workday function using vba?

  1. #1
    Registered User
    Join Date
    01-12-2014
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    77

    How to use Workday function using vba?

    Hi,

    I'm trying to insert the follwing line in a cell.
    "Please send the file on MM/DD/YYYY"

    I have written the following code, in which the date will be pulled from cell "B1".

    Sub autotext()
    Worksheets("Sheet1").select
    Range("D1").Value = "Please send the file on" & Space (1) & Format(Worksheets("Sheet1").Range("B1")) &
    End Sub

    But i want the date to be a working day. I have a list of holidays on my other worksheet. So how do i tell excel to put a working day, using vba?

    Thank you.

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: How to use Workday function using vba?

    Try something like this:
    Please Login or Register  to view this content.
    Note: Adjust the HolidayRange reference to suit your situation.



    Is that something you can work with?
    Last edited by Ron Coderre; 01-29-2014 at 10:15 AM.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Registered User
    Join Date
    01-12-2014
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    77

    Re: How to use Workday function using vba?

    Quote Originally Posted by Ron Coderre View Post
    Try something like this:
    Please Login or Register  to view this content.
    Note: Adjust the HolidayRange reference to suit your situaion.



    Is that something you can work with?
    Thank You Ron, that helped me a lot.

  4. #4
    Registered User
    Join Date
    01-12-2014
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    77

    Re: How to use Workday function using vba?

    Hi Ron,

    If the case is like 4 days after the date present in cell "B8". But only the fourth day should be working day, i.e if the 4th count falls on a non working day then moving to next working day.

    I've tried with the following code but did not get the desired result.
    Please Login or Register  to view this content.
    Can you please help me with this.

    Thank You.

  5. #5
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: How to use Workday function using vba?

    Try this:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-12-2014
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    77

    Re: How to use Workday function using vba?

    Hi,

    The above code is not working. I've attached my excel file. Can you please have a look at the file.

    Thank You.
    Attached Files Attached Files

  7. #7
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: How to use Workday function using vba?

    The VBA code needs to be in a general module...not a sheet module
    • ALT+F11...to open the VBA editor
    • Select your workbook from the project window
    • Insert.Module...to create a General Module
    • Cut the code from the "Actual" code module and paste it into the new module

    Last: Right-click on your button and assign the autotext macro to it.

    Does that help?

  8. #8
    Registered User
    Join Date
    01-12-2014
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    77

    Re: How to use Workday function using vba?

    I've moved the code to Module, but still not working.

  9. #9
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: How to use Workday function using vba?

    OK...Define "not working".
    When I follow the instructions I posted and click the button, the correct date is entered in the correct cell.

  10. #10
    Registered User
    Join Date
    01-12-2014
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    77

    Re: How to use Workday function using vba?

    When i enter the date as 3/1/14 and fourth day after the date is 3/5/14. since 3/5/14 is in holiday list, the result should be 3/6/14. But actual result is showing as 3/10/14.

  11. #11
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: How to use Workday function using vba?

    Got it....The WORKDAY function only counts actual workdays. However, it seems that you want to count actual days, including weekends, but not including holidays? Is that the rule?

    EDITED:
    I deleted my previous misguided effort because I think I figured out what you want.
    This code begins with the reference date, adds 3, then finds the next workday after that.
    Please Login or Register  to view this content.


    Is that something you can work with?
    Last edited by Ron Coderre; 02-04-2014 at 01:31 PM.

  12. #12
    Registered User
    Join Date
    01-12-2014
    Location
    India
    MS-Off Ver
    Excel 2016
    Posts
    77

    Re: How to use Workday function using vba?

    Thank You very much

+ 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. [SOLVED] Workday function help
    By emina002 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-10-2013, 08:47 AM
  2. Workday.INTL or Workday function issue
    By junoon in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-17-2013, 03:14 PM
  3. Workday function
    By Saky in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-31-2011, 09:56 AM
  4. Is there a better WORKDAY function?
    By Stubrok in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-19-2010, 04:45 PM
  5. Workday function
    By RUSH2CROCHET in forum Excel General
    Replies: 4
    Last Post: 05-17-2006, 02:40 PM

Tags for this Thread

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