+ Reply to Thread
Results 1 to 19 of 19

MACRO to check validation dropdowns left blank

  1. #1
    Registered User
    Join Date
    10-27-2008
    Location
    Manila, Philippines
    Posts
    11

    MACRO to check validation dropdowns left blank

    Need your help guys,

    I'm new at using macros - just learned a month ago.

    Any suggestions on this one:

    Got a table where I've placed Data validation - List on them.

    Placed a macro on a button so that the data on the table where the validation list is placed is transfered to another sheet (same workbook).

    What I need is a to modify the macro assigned to the button so that when the button is clicked to activate the macro:
    a.) Can identify if there are any blanks on specified cells with validation list
    b.) Stops the macro from copying the fields to the other sheet
    c.) Alert the user of the blanks (an alert stating there is a blank would suffice)
    d.) Alert should preferably be similar to a Stop alert from Data Validation.

    Can anyone help? Been reading through several threads but don't seem to find anything that could help me - tried reading a Visual basic thread and now i've got a headache....

    Whew...

    Thanks

  2. #2
    Registered User
    Join Date
    10-25-2008
    Location
    South East Asia
    Posts
    27
    Based on my limited VBA knowledge as well, the following procedure should work.
    Please Login or Register  to view this content.
    I think waiting for an expert's answer is better though.
    Last edited by XiaoWei; 10-27-2008 at 06:58 AM.

  3. #3
    Registered User
    Join Date
    10-27-2008
    Location
    Manila, Philippines
    Posts
    11

    Thumbs up

    Thanks

    Will try this tomorrow. After a few advils....

  4. #4
    Registered User
    Join Date
    10-27-2008
    Location
    Manila, Philippines
    Posts
    11
    Tried to use this but code won't work - Came back with error. Syntax Error.
    The first line got higlighted in yellow and the 2nd line got font color red.

    Any one please?

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try replacing

    Please Login or Register  to view this content.
    with

    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  6. #6
    Registered User
    Join Date
    10-25-2008
    Location
    South East Asia
    Posts
    27
    Hi,

    Thanks roy for pointing it out, I just realised that we can't use Resume label on same statement as On Error. But if we use GoTo label instead, the error condition will remain. Will it affect the subsequent statements if they ever get an error?

    By the way, this statement will select the entire spreadsheet, then filter to those with data validation of any type, then filter to blanks.
    Please Login or Register  to view this content.
    The better statement is to refer to a single cell, then select the range with same data validation and then blanks. For e.g.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-27-2008
    Location
    Manila, Philippines
    Posts
    11
    Thanks a lot guys.

    I'll give a try tomorrow

  8. #8
    Registered User
    Join Date
    10-27-2008
    Location
    Manila, Philippines
    Posts
    11

    Question

    Hi again,

    Tried the new code - this time no syntax error. Good.
    However when I run the code, even if the range or cell with validation is no longer blank the Msgbox indicating there is a blank still pops out and the copying does not proceed.

    I'd like to place the code here plus the copying code I recorded but don't know how to wrap the code.

    Thanks

  9. #9
    Registered User
    Join Date
    10-27-2008
    Location
    Manila, Philippines
    Posts
    11
    This is the code

    Please Login or Register  to view this content.
    RoyUK - Thanks for the link for wrapping codes

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Using code tags is simple. Selecyt the code that you post, then just click the button marked # above(this does not show in quick reply)

    The code works fine, no message if there are no blank cells

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Just checked your code, try this instead

    Please Login or Register  to view this content.
    Last edited by royUK; 10-29-2008 at 10:04 AM.

  12. #12
    Registered User
    Join Date
    10-25-2008
    Location
    South East Asia
    Posts
    27
    Hello again,

    Your code has some mistakes. Having seen Roy's code, On Error statement should not be there because the error will not occur under normal circumstance. Here's the modified code of Roy's.
    Please Login or Register  to view this content.
    However, this will check only one at a time. So if there are blanks in D6:E6 and D20 as well, the message box will prompt with first message (i.e. CA Name cannot be blank) only.
    Last edited by XiaoWei; 10-29-2008 at 10:30 AM.

  13. #13
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I forgot to delete that on error from the original

  14. #14
    Registered User
    Join Date
    10-27-2008
    Location
    Manila, Philippines
    Posts
    11
    When there is a blank the code works exactly the way Xiao outlined it above and I quote " However, this will check only one at a time. So if there are blanks in D6:E6 and D20 as well, the message box will prompt with first message (i.e. CA Name cannot be blank) only."

    However when all the specified ranges are not blank an error apppears

    400


    I see that the ranges set to be copied has been copied (highlighted). Can we assume the action or code stopped there then has an error.

    Note: I tried using both codes: first by Roy's then Xiao's but has the same result.

    Modified the code a bit to match the ranges. And changed the copying part of the code to simplify.

    Please Login or Register  to view this content.

  15. #15
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Can you attach the workbook?

  16. #16
    Registered User
    Join Date
    10-27-2008
    Location
    Manila, Philippines
    Posts
    11
    Attached is the workbook

    Thanks
    Attached Files Attached Files

  17. #17
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    The codes work if you put them in the right place. See the attached, you have placed this in the worksheet module.

    Add the code to a Standard module

    Also, remove all those empty modules.
    Attached Files Attached Files
    Last edited by royUK; 10-30-2008 at 10:26 AM.

  18. #18
    Registered User
    Join Date
    10-27-2008
    Location
    Manila, Philippines
    Posts
    11

    Talking It worked ! It worked!

    Thanks Roy.

    Work perfectly ! ! !

    Just had to move the 'Exit Sub' before the 'isBlank:'

    Thanks so much.


    How do I tag this thread as solved?

  19. #19
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I'll mark it solved, you can only o it when the thread is less than 48 hours old

+ 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