+ Reply to Thread
Results 1 to 3 of 3

Validating a List Selection

Hybrid View

  1. #1
    Registered User
    Join Date
    08-11-2010
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    6

    Validating a List Selection

    Is it possible to validate a list selection?

    I have 2 very simple lists which include Yes and No.

    The headings of the 2 columns are: Resident in California? and Resident in the USA?

    If the user selects Yes to the 1st question, then by default the user must select Yes to the second question.

    However, users might answer the 2nd question first. In that case, the user selects No to being resident in the USA, then by default the user must select No to being resident in California.


    At this point, I'm thinking of just introducing a column for error comments and using the traditional IF statements to validate the 2 columns.

    QUESTION: Is there a better solution ?

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Validating a List Selection

    see oeldere's links in this post...

    http://www.excelforum.com/excel-gene...alidation.html
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Validating a List Selection

    Hi
    first code will populate the USA question based on the California question
    2nd code will check if 1st question has been answered first

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Not Application.Intersect(Range("A2:A15"), Target) Is Nothing Then
            If Target.Value = "Yes" Then ' california
             Target.Offset(0, 1).Value = "Yes" 'USA
             Else
             Target.Offset(0, 1).Value = "No" 'USA
            End If
        End If
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Target.Cells.Count > 1 Then Exit Sub
           
        If Not Application.Intersect(Range("B2:B15"), Target) Is Nothing Then
            If Target.Offset(0, -1) = "" Then
            MsgBox "Answer California question first"
            Target.Value = ""
            Target.Offset(0, -1).Activate
            End If
        End If
        If Not Application.Intersect(Range("B2:B15"), Target) Is Nothing Then
            If Target.Offset(0, -1) = "Yes" Then
            Target.Value = "Yes"
            End If
        End If
    End Sub
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

+ 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