Consulting

Results 1 to 8 of 8

Thread: Solved: Data validation cell change - message box

  1. #1
    VBAX Regular
    Joined
    Oct 2005
    Posts
    33
    Location

    Solved: Data validation cell change - message box

    I have a cell which has a "yes/no" option using data validation. I want a messagebox to appear when the user selects "yes". I have tried "worksheet_change" but obviously the message keeps appearing when others cells are changed. I only want it to happen when the "yes/no" cell is changed. can anyone help?

    Thanks in adavnce

    Derek

  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    In the worksheet_change event check the target.row, target.column to see if that is the correct cell and then change otherwise don't.

  3. #3
    VBAX Contributor
    Joined
    Aug 2006
    Location
    Hampshire, UK
    Posts
    140
    Location
    Quote Originally Posted by Tommy
    In the worksheet_change event check the target.row, target.column to see if that is the correct cell and then change otherwise don't.
    Wouldn't just a check on Target.Address suffice?

  4. #4
    VBAX Regular
    Joined
    Oct 2005
    Posts
    33
    Location
    Can either of you help me with some sample code for your suggestions?

  5. #5
    VBAX Contributor
    Joined
    Aug 2006
    Location
    Hampshire, UK
    Posts
    140
    Location
    Something like:

    [VBA]If Not Intersect(Target, Range("YourCellAddress")) Is Nothing Then 'your cell is selected
    If Target.Value = "Yes" Then MsgBox "Your Message"
    End If[/VBA]

    In the worksheet_change event. Won't fire unless it is the specific cell that you reference in Range("YourCellAddress") bit.

    Richard

  6. #6
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Quote Originally Posted by RichardSchol
    Wouldn't just a check on Target.Address suffice?
    Looks to me they would be the same, six or half a dozen but good point

    [VBA]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Row = 1 And Target.Column = 1 Then
    MsgBox "!"
    End If
    If Target.Address = "$A$1" Then
    MsgBox "!!"
    End If
    End Sub
    [/VBA]

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    For me it works better with the validation if you use worksheet change:
    [VBA]Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then
    If Target.Text = "Yes" Then
    MsgBox "!!"
    End If
    End If
    End Sub
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  8. #8
    VBAX Regular
    Joined
    Oct 2005
    Posts
    33
    Location
    Guys, Thanks to you this code works beautifully. I have also written a worksheet deactivate code to change the cell back to "No" when exiting.

    This forum fixes my problems again!

    Thank you all.

    Derek

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •