+ Reply to Thread
Results 1 to 12 of 12

How to use Workday function using vba?

Hybrid View

  1. #1
    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:
    Sub Docdates()
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim HolidayRange As Range
    Dim dtMyDate As Date
    
    Set ws1 = Sheets("Data")
    Set ws2 = Sheets("Actual")
    Set HolidayRange = Worksheets("Sheet1").Range("D12:D16")
    
    dtMyDate = WorksheetFunction.WorkDay(ws1.Range("B8") - 1, 4, HolidayRange)
    
    ws2.Range("D1").Value = "Please send the file on " _
                            & Format(dtMyDate, "mm/dd/yyyy")
    
    End Sub
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  2. #2
    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

  3. #3
    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?

  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?

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

  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?

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

  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?

    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.

+ 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