Consulting

Results 1 to 4 of 4

Thread: Error Checking

  1. #1
    VBAX Newbie
    Joined
    May 2008
    Posts
    5
    Location

    Error Checking

    I'm not sure where to start with this one.

    I've two columns which are used to label data.

    Column A: Has 4 possible choices for the user to select.
    I've limited these selections by the use of a data validation drop down list.

    Column B: Is dependent upon the selection in Column A. So when a selection is made in Col. A a subset becomes available in Col. B using data validation.

    This work great at forcing users to enter only correct data. However, one problem can occur. A user can change column A after selecting column B. In which case the subset in B will not match column A.

    What I need is code to run in front of my macro which will test Column A and B to ensure everything is entered correctly.

    So some how it will ensure Column A is only the 4 possible selections (listed on the tab) & ensure that Column B is in the correct subset for Column A.

    Thanks in advance for the help.

    Doug

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Try this in the sheet change code:
    [VBA]Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 1 Then
    If Not Intersect(Target, Range("A:A")) Is Nothing Then
    Target.Offset(0, 1).ClearContents
    End If
    End If
    End Sub
    [/VBA]

    Example attached.....I used named ranges and indirect.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Very neat Steve.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Thanks Malcolm, after looking at this I thought it was a worthwhile idea. Dependent validation like this seems a little incomplete without it.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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