Forcing multiple data validations?

Here is my issue. In Cell G29 G30 G31 G32 G33 I have a list of values in a hidden sheet that they can key in a specific value from the list (this works). It uses data validation to confirm the value entered is in the list.

What I need to do now is add a second validation that checks to see if there is a value <> 0 in H29 H30 H31 H32 H33. If there is a value in H then check to make sure there is something keyed into G.

It doesn't matter how this is accomplished as long as it works.

Any thoughts? Is VB script in the sheet the best route? Is there a simple way I am not thinking about? Keeping in mind that I have no coding experience.

Thanks,
Ryan
LVL 1
Ryan RoodAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Add this to the worksheet and let me know if it does what you want.

Option Explicit
Private mbSelectedViaCode As Boolean
Private mrngOldCell As Range
Private Sub Worksheet_Change(ByVal Target As Range)
' When G is changed and H is blank then set the focus to H
If Not Intersect(Target, Range("G29:G33")) Is Nothing Then
    If Target.Value <> "" And Target.Offset(0, 1).Value = "" Then
        Application.EnableEvents = False
        mbSelectedViaCode = True
        Target.Offset(0, 1).Select
        Set mrngOldCell = ActiveCell
        Application.EnableEvents = True
    End If
End If

'If we are in H and G has a value, H can't be blank
If Not Intersect(Target, Range("H29:H33")) Is Nothing Then
    If Target.Value = "" And Target.Offset(0, -1).Value <> "" Then
        MsgBox "There must be a value in this cell if cell " & StripDS(Target.Offset(0, -1).Address) _
             & " is not blank. Changing " & StripDS(Target.Address) & " to " & Target.Offset(0, -1).Value & "."
        Application.EnableEvents = False
        Target.Value = Target.Offset(0, -1).Value
        Application.EnableEvents = True
    End If
End If

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If mbSelectedViaCode Then
    mbSelectedViaCode = False
    Exit Sub
End If
'If we were in H and G has a value, H can't be blank
If Not mrngOldCell Is Nothing Then
    If Not Intersect(mrngOldCell, Range("H29:H33")) Is Nothing Then
       If mrngOldCell.Value = "" And mrngOldCell.Offset(0, -1).Value <> "" Then
            MsgBox "There must be a value in this cell if cell " & StripDS(mrngOldCell.Offset(0, -1).Address) _
                 & " is not blank. Changing " & StripDS(mrngOldCell.Address) & " to " & mrngOldCell.Offset(0, -1).Value & "."
            Application.EnableEvents = False
            mrngOldCell.Value = mrngOldCell.Offset(0, -1).Value
            Application.EnableEvents = True
        End If
    End If
End If

End Sub
Private Function StripDS(strAddress As String)
    ' Remove the dollar signs from an address
    StripDS = Replace(strAddress, "$", "")
End Function

Open in new window

scsymeCommented:
An alternative is to implement conditional formatting such that when G is blank and H<>0 then G is highlighted red. Does that sound suitable, or do you need active interference?
Ryan RoodAuthor Commented:
@Martin Liss - thank you - I have not had a chance to attempt this yet ... will give it a go this afternoon.

@scsyme - yes and no, I am already doing this with my current solution but wanted something a little more vibrant to grab their attention.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Ryan RoodAuthor Commented:
@Martin Liss: When I add the code to my sheet nothing happens. Can you post a sample workbook with your code in it working so I can compare how you are setting your document up to mine?

Thanks,
Ryan
Martin LissOlder than dirtCommented:
It may or may not have been affecting your results, but I removed one variable in the attached workbook. The cells with data validation are blue.
Q-28627688.xlsm
Ryan RoodAuthor Commented:
I am trying to use your workbook as posted ... but I don't see anything happening? When data is typed in H29:H33 (any one), I want something to happen if there is nothing in G29:G33. Anything. An error message or something of the sorts that will pop up and warn them that they have not completed the field with data.
Martin LissOlder than dirtCommented:
OK, I misunderstood the requirements. In thought that if G29:G33 was changed that there needed to be something in H29:H33. Change a G29:G33 value. Do I have it backwards?
Ryan RoodAuthor Commented:
Yeah I think we are just off a little bit ... perhaps a bad explanation since only I know what I want. ;-)

Lets try this again:
If value is keyed into H29:H33 there must be a value in the corresponding G29:G33 range. If no value in G29:G33 pop an error warning them that they are missing a value in G29:G33.

Hopefully this is a little more clear.
Martin LissOlder than dirtCommented:
Please run the workbook and change a G29:G33 cell. Other than the fact that it's backward is it what you want?
Ryan RoodAuthor Commented:
Yes - this is exactly what I am looking for. Are you able to reverse it?
Martin LissOlder than dirtCommented:
Yes. Be back soon.
Martin LissOlder than dirtCommented:
Try this.
Q-28627688a.xlsm
Ryan RoodAuthor Commented:
This is what I am looking for ... one small thing ... can you disable adding the first value of the validation list? I just want them to get the error and the focus to move to this cell.
Martin LissOlder than dirtCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan RoodAuthor Commented:
Thank you very much for your assistance! This is exactly what I was trying to accomplish.
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.