+ Reply to Thread
Results 1 to 19 of 19

Prevent selection of a dropdown option if a different cell is empty

  1. #1
    Registered User
    Join Date
    09-24-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    13

    Prevent selection of a dropdown option if a different cell is empty

    Hi all,

    I'm new to the forum so bear with me! Running MS Excel 2010. Very new to VBA so just finding my footing. My problem is this:


    I have a large table of data with rows of tasks. The columns are things like the client name, the date the task was added, the employee assigned to the task, etc.

    One of the columns is the "Status" of the task - i.e. whether it is 'In Progress', 'Not Started', or 'Complete'. There is a dropdown using data validation for this column.

    I want the spreadsheet to be such that the user cannot choose the "Complete" option unless the 'Date Completed' field has been filled in (ie a message box appears).

    The table starts in cell B5 (ie the table headers are all in Row B).
    Status: Column G
    Date Completed: Column Q


    Can someone advise as to how I can write a macro to help me acheive this?

    Many thanks!

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Prevent selection of a dropdown option if a different cell is empty

    Hello pemb3545,

    Welcome to the Forum.

    With your Data Validation Dropdown in Column Q, enter this Formula: =IF(G4="",False,True)

    That is assuming your DV Dropdown Starts in Column Q Cell 4.

    Hope that helps

    Regards
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Prevent selection of a dropdown option if a different cell is empty

    Or you can add the following code to the worksheet module

    Please Login or Register  to view this content.
    If you like my contribution click the star icon!

  4. #4
    Registered User
    Join Date
    09-24-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Prevent selection of a dropdown option if a different cell is empty

    Hi guys

    Thanks so much for your responses. The code doesn't seem to work for me (I just copied and pasted into the worksheet module).

    Not sure if this makes a difference, but there are already lots of tasks (i.e rows of information) in the table already, and when i mark one of them as complete, nothing happens even though there is no completed date filled in Column Q. Any ideas?

    Thanks again!

  5. #5
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Prevent selection of a dropdown option if a different cell is empty

    Hello pemb3545,

    Have you tried my Formula? It does not require any VBA Code.

    Maybe you should consider uploading a small sample file, for us to see where things are going wrong.

    Regards

  6. #6
    Registered User
    Join Date
    09-24-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Prevent selection of a dropdown option if a different cell is empty

    Hi Winon,

    Sorry, I'm a bit confused by your suggestion. Just to reiterate, the data validation is in col G where the user selects the "Status"of their task and the date completed (col Q) is a freely typing field. Where should I place your IF formula?

    Thanks! Will try and get a sample file uploaded as well.

  7. #7
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Prevent selection of a dropdown option if a different cell is empty

    Hello pemb3545,

    Please see the attached sample Workbook.

    Regards
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    09-24-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Prevent selection of a dropdown option if a different cell is empty

    Ah it worked! Brilliant. Thanks so much!

  9. #9
    Registered User
    Join Date
    09-24-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Prevent selection of a dropdown option if a different cell is empty

    I spoke too soon! The way the formula works is that the user can mark a row as complete, and then simply not fill in the "Completed Date". They have to click on the "Completed Date" cell for the error message to come up.

    Ideally, I want it such that the person can't select completed and then just leave the row like that - they have to fill in the completed date. Any ideas?

  10. #10
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Prevent selection of a dropdown option if a different cell is empty

    Using the code I had provided earlier
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    09-24-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Prevent selection of a dropdown option if a different cell is empty

    That is awesome, thanks so much. It works perfectly - apart from one slight problem! There is already a macro in there that I've pasted below. It is to insert a new row at the bottom of the table with the same formatting (colours, date formatting) etc. When I click the button with that macro, I get the error message twice! Any thoughts? Thanks again!

    The macro may also be really bad code - i just tried recording and messing with it until it worked.

    Sub insertnewrow()

    Dim Lr As Integer

    Lr = Range("B" & Rows.Count).End(xlUp).Row

    Rows(Lr + 1).Insert Shift:=xlDown 'Ins

    Rows(Lr).Copy

    Rows(Lr + 1).PasteSpecial Paste:=xlPasteFormats

    Application.CutCopyMode = False

    End Sub

  12. #12
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Prevent selection of a dropdown option if a different cell is empty

    just a quick answer without going into the logic.

    Add the following at the start of your routine

    Please Login or Register  to view this content.
    Add the following at the end of your routine

    Please Login or Register  to view this content.

  13. #13
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Prevent selection of a dropdown option if a different cell is empty

    Hello pemb3545,

    In your Post # 6, you said:

    Thanks! Will try and get a sample file uploaded as well.
    Without seeing what you have set up how, Code, formulae and all, I will not be able to assist you any further, as I do not like playing guessing games.

    Regards

  14. #14
    Registered User
    Join Date
    09-24-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Prevent selection of a dropdown option if a different cell is empty

    Sorry Winon - never got round to making a sample and couldn't upload the whole thing because of names of clients etc! Ollie - it worked perfectly. Thanks for all of your help both!

  15. #15
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Prevent selection of a dropdown option if a different cell is empty

    Hello pemb3545,

    All fine and well, no harm.

    Please just remember when you post Code like you did in Post # 11, to wrap your Code as required by Forum Rules.

    Regards

  16. #16
    Registered User
    Join Date
    09-24-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Prevent selection of a dropdown option if a different cell is empty

    Hi all - An additional question related to this. The code in post #10 works perfectly - until I want to add or delete a row. When I do so, I get the error message "Status cannot be completed without providing a completion date".

    Any ideas? Thanks!

  17. #17
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Prevent selection of a dropdown option if a different cell is empty

    Hello pemb3545,

    Replace the Code in your Worksheet_Change Event, with the Code below.

    Please Login or Register  to view this content.
    Regards.

  18. #18
    Registered User
    Join Date
    09-24-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Prevent selection of a dropdown option if a different cell is empty

    Winon - this is awesome, thanks!

  19. #19
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Prevent selection of a dropdown option if a different cell is empty

    Hello pemb3545,

    You are welcome.

    Glad I could help.

    If you are satisfied with the solution I had given you, then please mark your Thread as Solved.

    You may also Click on the Star to the far left, at the bottom of this Post, to Add Reputation.

    Regards

+ 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] Looping through cell ranges in multiple worksheets and prevent saving if cell value empty
    By Spritz in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-22-2013, 11:24 AM
  2. Replies: 3
    Last Post: 09-20-2012, 03:11 PM
  3. Prevent text from being entered, if above cell ist empty
    By FallingDown in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-19-2012, 04:51 AM
  4. Replies: 2
    Last Post: 08-11-2011, 01:32 AM
  5. How do I change the cell colour per dropdown option?
    By Emma962 in forum Excel General
    Replies: 1
    Last Post: 08-11-2006, 10:10 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