+ Reply to Thread
Results 1 to 18 of 18

Macro to add to date in selected cell by one working day

  1. #1
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Macro to add to date in selected cell by one working day

    Afternoon,

    I'm after a macro that will bring up a box in which I can enter the number of working days that I want to add to the date in the selected cell. So, the selected cell may contain Monday's date. When I click to run the macro, and put 3 working day's in the box, it should come up with Thursday's date. Alternatively, if it had Friday's date in, and I put 2 in the box, it should say Tuesday's date.

    Can anyone help?

    Many many thanks

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Macro to add to date in selected cell by one working day

    what about if you are on Wednesday and you put in 4 and it lands on Sunday?....do you want it to bump to Monday?
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Macro to add to date in selected cell by one working day

    Well, if it's wednesday and I enter 4, then I would want it to go to Tuesday, because that is 4 working days away.

    Is it understandable or not? Basically i want to dis-count the weekends

  4. #4
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Macro to add to date in selected cell by one working day

    excellent, that what I needed...thanks

  5. #5
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Macro to add to date in selected cell by one working day

    cool, will wait to hear

  6. #6
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Macro to add to date in selected cell by one working day

    sorry it's taking some time....I actually have to do work...go figure....it may be a bit....if somebody else has a faster answer, go for it....again, sorry

  7. #7
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Macro to add to date in selected cell by one working day

    no worries

  8. #8
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Macro to add to date in selected cell by one working day

    this seems to work on the dates I tried....thanks for your patience...

    Please Login or Register  to view this content.

  9. #9
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Macro to add to date in selected cell by one working day

    you can wrap the whole sub in an IF ISDATE(cell) statement to make sure you are in a cell with a date

  10. #10
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Macro to add to date in selected cell by one working day

    OK, any ideas on how? Just a worksheet event?

    Also, I'm assuming this needs a userform?

  11. #11
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Macro to add to date in selected cell by one working day

    if you are talking about how to launch the macro, then I would add it to the quick access toolbar...you can add macros to the QAT and then click in the date cell, click on the macro icon on the QAT and it will launch the macro....you'll get the input box to ask how many days...and, hopefully, adjust that day correctly....HTH

  12. #12
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Macro to add to date in selected cell by one working day

    here is the ISDATE code

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Macro to add to date in selected cell by one working day

    Excellent thanks.

    One minor hitch. When I do 11/09/2013 and add 4 days it goes to 16/09/2013 as opposed to 17/09/2013

    Any ideas?

  14. #14
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Macro to add to date in selected cell by one working day

    try this

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Macro to add to date in selected cell by one working day

    Excellent - works perfectly. You're a saint!

  16. #16
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Macro to add to date in selected cell by one working day

    thanks....I'm glad I could help....and I'm pretty sure I haven't done any actual miracles....but thanks anyway.....

  17. #17
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Macro to add to date in selected cell by one working day

    Please remember to set the thread to SOLVED...thanks

  18. #18
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Macro to add to date in selected cell by one working day

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

    I will also add that this situation is a perfect one to use the built-in function WORKDAYS, which also allows you to give a list of holidays in addition to taking care of the weekends for you. It saves doing a lot of date arithmetic logic from scratch. It can be called from VBA code using Application.WorksheetFunction.WORKDAY.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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. Auto Saving Macro Based on Selected Date
    By Grabaka in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-26-2013, 09:11 AM
  2. [SOLVED] Macro to add date move 5 collums right add next working day date
    By davechamp1983 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-17-2012, 03:42 PM
  3. [SOLVED] Macro to copy selected blocks of data not working
    By Authentik8 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-17-2012, 05:06 AM
  4. Need Macro to copy lines depending on agent selected and date range
    By eglassburn in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-22-2010, 07:22 PM
  5. Macro to take selected cells times a selected cell
    By Craig in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-23-2005, 08: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