+ Reply to Thread
Results 1 to 11 of 11

Clear Cell After Messagebox

  1. #1
    Forum Contributor
    Join Date
    01-30-2011
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    102

    Clear Cell After Messagebox

    I have a grid of cells that evaluate to "yes" (true) or "no" (false)

    Upon entering a name in a particular range of cells, J7:J165, if a particular condition evaluates to true, I would like a message box to appear, warning of the error, and then clear the name out of the cell and keep the focus on it.

    It would look something like:

    a name gets picked from a drop down menu in cell J7

    One of the conditions would be in cell J172. If it's "no", nothing happens, if it's true, then how I currently have it set up is that it calls a public function, for instance, availabilitycheck(),....the formula in cell J172 is:

    =IF(OR(Schedule!B7<VLOOKUP(J7,EmpInfo!$C$3:$V$200,7,FALSE),((IF(F7="close",(MOD($AE$4-B7,1))*24,(MOD(F7-B7,1))*24))>=MOD(VLOOKUP(J7,EmpInfo!$C$3:$V$200,8,FALSE)-Schedule!B7,1)*24)),availability(),"no")

    The function contains the message box, and it is here I would like to also be able to clear the contents of the selected cell.

    I had a similar question not too long ago, and the solution was:

    Please Login or Register  to view this content.
    I also experimented with this, not as a public function, obviously......

    I tried substituting Vlookup in place of the worksheetfunction.countif, and taking out the function call in the excel vlookup formula and replacing with "yes" (as the vlookup formula would evaluate to "yes" or "no", but I could not get the vba code to work.

    In the vb code, to locate the cell in question that would potentially throw up the messagebox, the vlookup expression would take the value in the cell that the name was dropped in, then check it against the range B172:Q330, the cell that contains the true/false value would be 9 columns over.....the range is greater than 9 columns because I would just use this a constant range, just change the # of columns where necessary.

    I thought maybe the fact that the "cell" that the name gets dropped in was actually a collection of merged cells was the culprit, but the code I included here from a previous response works on the same range, and does exactly what I want to do in this situation.

    I explain things horribly, so +rep if you even understand what I just wrote......
    Last edited by ZooTV92; 08-18-2011 at 07:07 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,603

    Re: Clear Cell After Messagebox

    Please post a sample workbook so the code and data can be tested in context.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    01-30-2011
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    102

    Re: Clear Cell After Messagebox

    attached.....thank you!
    Attached Files Attached Files

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,603

    Re: Clear Cell After Messagebox

    Apologies: I did look at the workbook. I can see how the current code works but, sadly, I don't really understand what you want to do differently.

    I'll see if I can get someone else to have a look.

    Regards

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Clear Cell After Messagebox

    your current code seems to check the current column for duplicates. What is the purpose of the "yes" in the rows below?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  6. #6
    Forum Contributor
    Join Date
    01-30-2011
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    102

    Re: Clear Cell After Messagebox

    The grid at the bottom checks each name against certain conditions. If a condition comes up as a "yes", it pops a message box, which is easy enough. How I would like it to work is that upon clicking "yes" in the messagebox, the contents of the cell that the name was dropped in should be cleared, and the focus remain on that cell. I cannot get that part to work.

    The formula that checks for duplicates works exactly the way I want the rest of it to work. If a name that gets dropped is a duplicate, then it pops the messagebox, and the name is cleared out of the cell.

    Currently, J172 is the only cell I have experimented with that calls a public function if the formula evaluates to true. The function is located in module 4. I have also toyed around with using Vlookup in the same code that the duplicate check is set up in. I cannot get any combination to clear the contents of the cell after the message box is acknowledged.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Clear Cell After Messagebox

    1) Change the named range EmpList Refers To: formula to this:

    =OFFSET(EmpInfo!$C$3,,,COUNTA(EmpInfo!$A:$A)-1,1)

    2) Simplified some EmpInfo formulas

    C3: =B3&", "&A3
    E3: =DATEDIF(D3,TODAY(),"y")

    Also, the ADD EMPLOYEE macro now adds these formulas properly including cleaned up phone numbers.

    3) Schedule:

    - drop down list will not show employees until you fill in a shift
    - A6 is a drop down for jobs, used later to check the job certifications
    - Not sure any of the stuff at the bottom is needed anymore
    - This is the new sheet code:
    Please Login or Register  to view this content.
    4)
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    01-30-2011
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    102

    Re: Clear Cell After Messagebox

    That is going waaaaayyyyy above and beyond.

    Your invested time is greatly appreciated. Hopefully I can make enough sense out of it to make the rest of the conditions work

    Regards

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Clear Cell After Messagebox

    If the conditions are more jobs, just add them as shown and the existing code will check for those jobs, too.

    If it's new kinds of conditions, the samples I gave for checking TimeOFF, Availability and Job Certifications by job name should provide a basis for developing new tests.

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  10. #10
    Forum Contributor
    Join Date
    01-30-2011
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    102

    Re: Clear Cell After Messagebox

    Just for S's and giggles, is there a way to do what I was looking for in the beginning, and that is when a specific cell turns to "yes", it launches a messagebox warning of an error, and then clears the contents of the cell that the name was dropped in (merged cells - and I can't change that) while keeping the focus on that cell?

    To be honest, your code, while impressive, is a little beyond my understanding, and for me to look forward, I need to be able to understand what I'm looking at.

    The assistance of this board is and always will be appreciated.

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Clear Cell After Messagebox

    We're all about teaching! Hehe, streeeeeeeeeetch....

    Here's the code again with more guidelines about what each line does, let's look through the code and find what isn't logical to you yet. Use F8 to activate the macro and step through the code one line at a time, after each code executes, hover your mouse over the variables to see the results, and check the sheets to see how it got those answers.

    Please Login or Register  to view this content.

    Meanwhile, a simple way to check if a cell cell "yes" in a specific distance away/below:

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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