+ Reply to Thread
Results 1 to 9 of 9

Macro to show a message box if even one cell in a row is blank

  1. #1
    Registered User
    Join Date
    02-16-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    9

    Question Macro to show a message box if even one cell in a row is blank

    Hi,

    I have created a macro that highlights all blank cells in a row to be highlighted in purple background using conditional formatting.
    What I am struggling with is that I need a macro to show a message box if even one cells in a row from A2:AI2 is blank and is highlighted in the purple colour conditional formatting.
    If there are no blank cells in the row (only till AI2) I want it to state "Completed" and if even one cell is blank from A2:AI2, it should show a message box stating "Please fill all blank cells highlighted in purple"

    This is very urgent so I would appreciate your help.

    Thanks,
    Pat

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Macro to show a message box if even one cell in a row is blank

    Please Login or Register  to view this content.
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Macro to show a message box if even one cell in a row is blank

    Sorry Guys

    The above code will not check for the colour purple. Try This instead.


    Please Login or Register  to view this content.

  4. #4
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Macro to show a message box if even one cell in a row is blank

    all blank cells in a row to be highlighted in purple background using conditional formatting
    Since the OP is using Conditional Formatting to set the cell fill color based on the cell being blank, there is no need to perform this color check in code, therefore I did not code for it.

    Looping seems pointless for this given the vary narrow range of cells.
    In VBA there is rarely a need to select cells since you may directly act on objects.

    Your loop is going down column-A, where as the OP specified row-2, columns-A:AI
    Last edited by Palmetto; 02-26-2013 at 07:46 PM.

  5. #5
    Registered User
    Join Date
    02-16-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Macro to show a message box if even one cell in a row is blank

    Palmetto, your code worked perfectly!!!
    Thank you so much

  6. #6
    Registered User
    Join Date
    02-16-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Macro to show a message box if even one cell in a row is blank

    I need to tweak this formula slightly to pick up a variable range. Instead of (A2:AI2), I want to select A2:AI2 and then select all visible rows below row 2 if column A is not blank.
    So, if B3 had any text in it, the macro should also check A3:AI3 and so on..

    Can anyone help me tweak the code to include this variable range?

  7. #7
    Registered User
    Join Date
    02-16-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Macro to show a message box if even one cell in a row is blank

    I need to tweak this formula slightly to pick up a variable range. Instead of (A2:AI2), I want to select A2:AI2 and then select all visible rows below row 2 if column A is not blank.
    So, if B3 had any text in it, the macro should also check A3:AI3 and so on..

    Can anyone help me tweak the code to include this variable range?

  8. #8
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Macro to show a message box if even one cell in a row is blank

    This revised code will determine the last used row based on column-A and loop through each row counting blank cells.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-16-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Macro to show a message box if even one cell in a row is blank

    Thanks, Palmetto. Once again your code works perfectly
    I only wanted to make one change to it. The macro runs all the way to "Completed" even if there are blank cells present in the variable range.
    Would it be possible to make it stop if there are blank cells present and only show the "Completed" message box if all blank cells are filled in.
    I do not know how to make the if function work in the code.. here's what I tried:
    Please Login or Register  to view this content.
    Pat

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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