+ Reply to Thread
Results 1 to 16 of 16

Need VB code to trigger popup when any date in a range is within 30 days of system date.

  1. #1
    Registered User
    Join Date
    03-19-2018
    Location
    Liverpool
    MS-Off Ver
    365 2013
    Posts
    14

    Need VB code to trigger popup when any date in a range is within 30 days of system date.

    Hello all, I have searched the forum for a solution and tried various options but cannot find a line of code to select dates from a range.

    I have a spreadsheet that lists items of equipment that have to be calibrated or serviced regularly, the 'Due Dates' are all in one column. Can you help me with VB code to look at the entire column (i2:i100) and select any (duedate) that falls within 30 days of the system date and which will, in turn, activate my (msgbox)?

    Thanks, Dave.

    N.B. I forgot to define that I need the macro to run when the (workbook) is opened, also I have already created my (msgbox) which works fine.

    Dave.
    Last edited by enthusiastic learner; 04-01-2019 at 07:37 AM.

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Need VB code to trigger popup when any date in a range is within 30 days of system dat

    Hi, quick and dirty but this is the code

    Please Login or Register  to view this content.
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    03-19-2018
    Location
    Liverpool
    MS-Off Ver
    365 2013
    Posts
    14

    Re: Need VB code to trigger popup when any date in a range is within 30 days of system dat

    Thanks so much for your help, I have added your code and found that the (msgbox) continues to appear whatever key I press. I have to close excel via task manager to stop it.
    I have attached a copy of the code as written, can you advise?

    Thanks, Dave.
    Attached Files Attached Files

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Need VB code to trigger popup when any date in a range is within 30 days of system dat

    I don't know why you're post a word doc, use notepad or Excel next time!!

    Modified the code a little

    Please Login or Register  to view this content.

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,670

    Re: Need VB code to trigger popup when any date in a range is within 30 days of system dat

    Hi there,

    Just a suggestion - it might be more effective to use Conditional Formatting to indicate those cells which contain "almost out of date" values, and then to exit from the loop as soon as the message has been displayed for the first date cell identified.

    As I said, just a suggestion.

    Regards,

    Greg M

  6. #6
    Registered User
    Join Date
    03-19-2018
    Location
    Liverpool
    MS-Off Ver
    365 2013
    Posts
    14

    Re: Need VB code to trigger popup when any date in a range is within 30 days of system dat

    Morning Keebellah, again, thank you for your assistance and advice with my project. I have applied your suggested code and found that the message box appears even if a date on my spreadsheet is over 60 days in the future. Also, the number of 'days remaining ' in the (msgbox) do not always add up correctly.
    I am new to VB code, so I do not fully understand your code. if you could add comments to the code I may be able to figure it out for myself?

    That said, it is helping me see the bigger picture.

    Thanks again,
    Dave.

  7. #7
    Registered User
    Join Date
    03-19-2018
    Location
    Liverpool
    MS-Off Ver
    365 2013
    Posts
    14

    Re: Need VB code to trigger popup when any date in a range is within 30 days of system dat

    Hi Greg, thanks for your suggestion. As it happens, I have managed to use Conditional Formatting in the 'date cells' to provide coloured icons which aid a quick eye scan but I need to add popup's because I need a prompt for the users to open the sheet and look for themselves.

    Is it possible then to add more Conditional Formatting to the same set of (cells) as you suggest and if it is, could you advise on a (formula)?

    Cheers,

    Dave.

  8. #8
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,670

    Re: Need VB code to trigger popup when any date in a range is within 30 days of system dat

    Hi again,

    Does the attached workbook get you moving in the right direction?

    It uses Conditional Formatting to highlight dates which require attention, and the following code to alert the User if any do need attention:

    Please Login or Register  to view this content.
    The highlighted values may be altered to suit your requirements.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Need VB code to trigger popup when any date in a range is within 30 days of system dat

    Quote Originally Posted by enthusiastic learner View Post
    Morning Keebellah, again, thank you for your assistance and advice with my project. I have applied your suggested code and found that the message box appears even if a date on my spreadsheet is over 60 days in the future. Also, the number of 'days remaining ' in the (msgbox) do not always add up correctly.
    I am new to VB code, so I do not fully understand your code. if you could add comments to the code I may be able to figure it out for myself?

    That said, it is helping me see the bigger picture.

    Thanks again,
    Dave.
    What more is there to add to the code,first of all it's your own code and second it explains itself, all you need to do is add a condition that a date in the future is ignored
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    03-19-2018
    Location
    Liverpool
    MS-Off Ver
    365 2013
    Posts
    14

    Re: Need VB code to trigger popup when any date in a range is within 30 days of system dat

    Hi Greg, this looks like just what I need. However, I have been trying to apply it to my worksheet and cannot get past the "details" part. I get an error 'Runtime error 9, Subscript out of range'

    I have been trying the 'sheet' name i,e, 'sheet14' also the tab name 'Bodyshop_Calibrations'

    Do I need to give my worksheet a name in the properties box?

    Dave

    NB

    Ok,what a **** I am. I have finally figured out the 'Name' problem and can step through the code when applied to my sheet but I still cannot get the message to appear on que. I will look again before asking for further help.

    Cheers, Dave.
    Last edited by enthusiastic learner; 04-06-2019 at 03:24 AM.

  11. #11
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Need VB code to trigger popup when any date in a range is within 30 days of system dat

    A NOTE for you as upcomming programmer: Remember that VBA is very 'stupid' in the sense that it does exactly what YOU tell it to do not the other way around so everything explicitly named must also exist in the same way YOU enter it in the VBA code and on the worksheets, tabs, fields, etc.
    In mavy cases some actions unless explicitly not told are also case sensitive.

  12. #12
    Registered User
    Join Date
    03-19-2018
    Location
    Liverpool
    MS-Off Ver
    365 2013
    Posts
    14

    Re: Need VB code to trigger popup when any date in a range is within 30 days of system dat

    Right, thanks.

  13. #13
    Registered User
    Join Date
    03-19-2018
    Location
    Liverpool
    MS-Off Ver
    365 2013
    Posts
    14

    Re: Need VB code to trigger popup when any date in a range is within 30 days of system dat

    Hi Greg, your code will do what I need. My (workbook) has seven sheets, all of them contain the (target) cells in column "I". I just have two questions, first, do I apply the code just once to the (workbook) properties page and if so how do I refer to the individual sheets in the same line?

    Const sSHEET_NAME As String = "Details"

    Thanks,
    Dave.

  14. #14
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Need VB code to trigger popup when any date in a range is within 30 days of system dat

    Use a for loop to check all sheets
    What's the code you have so far?
    Or do you want Greg's code to handle all sheets?

    You will have to move the code to a common module and edit it accordingly but sure Greg will update

  15. #15
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Need VB code to trigger popup when any date in a range is within 30 days of system dat

    Modified Greg's code and it can be used for as many sheets as you have, condition is that Column I is always the Due date column

    Edit for dynamic if you have more than 100 rows

  16. #16
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,670

    Re: Need VB code to trigger popup when any date in a range is within 30 days of system dat

    Hi Keebellah,

    Thanks for looking after this while I was away on holidays

    Regards,

    Greg M

+ 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. Email Trigger needed 30 days before an MOT Expiry date.
    By gempinkfairy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-27-2014, 05:48 AM
  2. Replies: 1
    Last Post: 05-26-2014, 03:46 AM
  3. Replies: 2
    Last Post: 10-06-2013, 02:03 PM
  4. Replies: 5
    Last Post: 10-02-2013, 09:49 AM
  5. Search date range +/- 7 days and return date that falls within range
    By tlafferty in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-13-2013, 03:26 PM
  6. Code to popup a message box after 15 days of the inserted date
    By hunmus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2012, 01:33 PM
  7. [SOLVED] How can I get a date in exel to trigger a reminder in 30 days?
    By tigerfan in forum Excel General
    Replies: 0
    Last Post: 03-13-2006, 07:15 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