+ Reply to Thread
Results 1 to 11 of 11

MsgBox if any cell within range is blank

  1. #1
    Registered User
    Join Date
    04-18-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    4

    MsgBox if any cell within range is blank

    Hi,

    This is my first post and I'm new to VBA. I'm trying to highlight any blank cells and display a message saying "there are incomplete fields" if any cells within a range are blank. I have created a button and managed to get the code to highlight any blank cells in yellow, I'm struggling to get the message box to only appear once, the best I've managed so far is it appears as the macro checks every cell. This is my current code:
    Please Login or Register  to view this content.
    This might confuse things further but I also have conditional formatting grey out some cells that don't require completion depending on what category is selected, I think the current code still colours those cells in yellow as they are left blank and then the conditional formatting just puts the grey over the top (so the yellow isn't visible). I would need the error message to only count blank cells that the conditional formatting doesn't grey out. Is that possible?

    Thanks in advance

    Sam

    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Attached Files Attached Files
    Last edited by Samanthabenton; 04-25-2016 at 06:58 AM. Reason: solved

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

    Re: MsgBox if any cell within range is blank

    This might confuse things further but I also have conditional formatting grey out some cells that don't require completion depending on what category is selected, I think the current code still colours those cells in yellow as they are left blank and then the conditional formatting just puts the grey over the top (so the yellow isn't visible). I would need the error message to only count blank cells that the conditional formatting doesn't grey out. Is that possible?
    The code can't detect whether a cell is colored due to conditional formatting. The only way to detect this in code is to use the same logic in the code that is used in the conditional formatting.

    Can you attach your file?
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    04-18-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    4

    Re: MsgBox if any cell within range is blank

    Hi,

    I've attached the file. Thanks for correcting the original post, I couldn't work out how to get the code to appear correctly.

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

    Re: MsgBox if any cell within range is blank

    Here is one suggestion I am working on. I would move the logic for your grayed-out fields into the worksheet. This makes your conditional formatting rules much simpler, and allows the code to be simple as well.

    I have made a copy of your Model Exceptions Proforma sheet and called it Gray Flags. For any field that can be grayed out, I have put the formulas from the original conditional formatting directly into the fields in the Gray Flags sheet to produce an "X" in the field when it's supposed to be grayed out. Then the conditional formatting rule in Model Exceptions Proforma simply checks for an X in its corresponding cell in Gray Flags. This allows you to use a single simple conditional formatting rule to cover all the possible gray cells. You can hide the Gray Flags sheet so the user never sees it.

    Then it also becomes very easy for the code to make the same check.

    But before I do any more work I want to understand your conditional formatting rule. For example for the block starting in A57, your rule is

    =AND(OR($H$15="Transactions over £1k (Local Model Only)",$H$15="Back Office Terminal",$H$15="Increase/ Decrease of Counter Positions",$H$15="Opening Hours",$H$15="Opening Hours",$H$15="service point on retail till (main model only)",$H$15="Branch Format"),$H$16<>"Saturday Afternoon Opening Hours (Main Model Only)")

    The OR part of this checks every possible choice other than "Saturday Afternoon Opening Hours (Main Model Only)". Is there any reason we can't use this much shorter formula that is logically equivalent:

    =AND($H$15<>"Saturday Afternoon Opening Hours (Main Model Only)",$H$16<>"Saturday Afternoon Opening Hours (Main Model Only)")

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

    Re: MsgBox if any cell within range is blank

    On second look I see that if both H15 and H16 were blank, all areas would be grayed out. That is different than you current logic but I think it would be appropriate.

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

    Re: MsgBox if any cell within range is blank

    I just remembered that CF rules cannot refer to other sheets. Let me give this another thought.

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

    Re: MsgBox if any cell within range is blank

    Give this a try. Rather than a hidden sheet, I put the formulas into hidden columns on the same sheet.

    If this works the way you want, then we can look at the code.
    Attached Files Attached Files

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

    Re: MsgBox if any cell within range is blank

    Another thought--it would be more effective to use CF to color blank cells yellow. If you do it in the code, then you have to run more code to clear the yellow. Using CF provides a way to prompt the user in real-time for what they need to fill in. Here is an update using that approach plus the code to check.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    04-18-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    4

    Re: MsgBox if any cell within range is blank

    Hi, thank you so much for your help so far. The CF to grey out looks to be working as its supposed to, just as a note H15 and H16 wouldn't ever both be blank, H15 would always have a value.

    Ideally I would like the yellow only to appear when the button is clicked, and to include the white cells within rows 5-55 and row 98 to highlight, like in the previous version you uploaded.

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

    Re: MsgBox if any cell within range is blank

    I assume that H15 and H16 would both be blank as soon as a new form is opened, so all those sections are gray before the user enters any data.

    Here is a revision that turns blank cells yellow only when the button is clicked. Therefore any yellow will be cleared only the next time the button is clicked.

    I added a ClearAllFill Sub that can be used for testing or for cleanup. This will clear the fill color in all the required cells. To ensure that it is using the same cells as the sub for the button click, I declared the Range string as a global constant at the top of the module. That way if you ever change the form, you just need to update the range in one place. (BTW the "=" in the Range string is unnecessary so I removed it.)
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    04-18-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    4

    Re: MsgBox if any cell within range is blank

    that's perfect, thanks again for your help

+ 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. Display msgbox once if any cell in range is a specific color
    By anthronewman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2015, 04:32 PM
  2. Replies: 3
    Last Post: 07-21-2015, 09:15 AM
  3. VBA if active cell blank than msgbox to remind
    By dekueb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-14-2015, 10:48 AM
  4. Replies: 2
    Last Post: 11-22-2013, 01:07 PM
  5. [SOLVED] MsgBox when a cell within a range changes to a specific value
    By kitackers in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-20-2012, 08:49 AM
  6. MsgBox if the Active Cell is not within a preferred Range
    By Winon in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-03-2011, 05:52 AM
  7. How to show MsgBox if a any cell value is > 17 in a range
    By syedalamgir in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-12-2011, 08:48 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