+ Reply to Thread
Results 1 to 4 of 4

Excel 2007 VBA Message Box with criteria

  1. #1
    Registered User
    Join Date
    12-03-2013
    Location
    Darlington, England
    MS-Off Ver
    Excel 2007
    Posts
    18

    Excel 2007 VBA Message Box with criteria

    Hi I am VERY new to VBA and am starting to get confused!

    I have a spreadsheet that monitors employees rest periods between shifts across a number of weeks I've started writing a very basic piece of code so if the employee has less than 12 hours rest, a message box will appear with a warning:

    So far this is what I've done:

    Sub RestHours()

    If Range("I7") < #12:00:00 PM# Then

    MsgBox "Candidate has had less than 12 hours rest since last shift worked. Please find another candidate to work this shift", vbOKOnly, "Unable to Use Candidate!"


    Now this does work if I run the macro and then enter the data into cell I7, however I'm now stumped - How can I make it so that this message box pops up automatically when the data is entered into the cell without me have to go in and run the macro?

    I also need the macro to run all the way down the I column (I7:I100) and across other columns which will eventually contain the same data i.e. M7:M100, Q7:Q100, all the way across to AT7:AT100? If its any help the columns have the same title (Total Rest Hours)

  2. #2
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Excel 2007 VBA Message Box with criteria

    Hi,


    use this code :

    Please Login or Register  to view this content.
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  3. #3
    Registered User
    Join Date
    12-03-2013
    Location
    Darlington, England
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Excel 2007 VBA Message Box with criteria

    Hi Xlbiznes,

    Thanks for this - I dont quite understand how to use this piece of code - do I need to put the piece I had already written in somewhere? I think at the moment I need things spelling out to me very simply

  4. #4
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Excel 2007 VBA Message Box with criteria

    Just copy this code into the code behind of the sheet let us assume that the cell I7 that you are trying to use is in sheet1.

    You need to put this code into the code for this sheet.

    Click on the developer tab and then visual basic.

    On the right side you will see the project explorer.

    Under Microsoft excel objects you will see you sheet names. Double click on the sheet name and you will see the code behind of that sheet on the right side.

    Paste the code in the empty white space and try the code by entering any value in the cell "I7".

+ 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] Excel 2007 : Sorting - Message re Removed Records
    By Richard Buttrey in forum Excel General
    Replies: 34
    Last Post: 11-19-2021, 02:32 AM
  2. What is Message Bar under the view tab in excel 2007?
    By hariprof in forum Excel General
    Replies: 5
    Last Post: 02-25-2010, 12:28 PM
  3. Filtering by More Than Two Criteria in Excel 2007
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 11-27-2007, 09:05 AM
  4. Replies: 0
    Last Post: 11-15-2007, 03:40 AM
  5. Replies: 0
    Last Post: 10-31-2007, 10:00 AM

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