Results 1 to 3 of 3

Thread: list validation in excel; what if an item in list changes??

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    13

    list validation in excel; what if an item in list changes??

    Hello,

    I have a used a list validation in my excel sheet,
    which works fine when i want to insert a value from
    a specified list in a cell.

    (the specific list is specified in A1:A3):
    A1:YES
    A2:NO
    A3:NO COMMENT

    but now, if i change for example in the list A3
    from "NO COMMENT" to "UNSPECIFIED" i have the following
    problem:
    - all cells linked to the list (that now changed) where
    previous "NO COMMENT" was correctly validated should
    not be valid anymore since an item in my list changed.

    Excel does not do this automatically. In a new cell i can
    choose between the three items correctly, but what about the
    old cells! they are corrupt (against my new list and excel doesn't see this!)

    can i enable this autocheck on change or is there a function in vba or something that forces the validation?

    what now???

  2. #2
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: list validation in excel; what if an item in list changes??

    to start off, you will need to copy the current values to another location on 'worksheet_activate' to reference if the list range changes.

    then set the range (e.g. give it a name), and you should be able to reference it in code.
    VB Code:
    1. Range("MyBook.xls!ListRange")

    when it changes you check the values to the values you copied on activate, and if different, do a find/replace of the old value for the new.

    heres come quick code:
    VB Code:
    1. Sub CheckValues()
    2.  
    3.     Dim intcount As Integer
    4.    
    5.     intcount = 1
    6.    
    7.     For Each c In Range("ListRange")
    8.         If c.Text <> Range("B" & intcount).Text Then
    9.                 Cells.Replace What:=Range("B" & intcount).Text, Replacement:=c.Text, LookAt:=xlPart, _
    10.         SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    11.         ReplaceFormat:=False
    12. intcount = intcount + 1
    13.         End If
    14.     Next c
    15.  
    16. End Sub
    17.  
    18. Private Sub Worksheet_Activate()
    19.  
    20. 'copy values to next column
    21.     Range("A1:A3").Select
    22.     Selection.Copy
    23.     Range("B1").Select
    24.     ActiveSheet.Paste
    25.     Application.CutCopyMode = False
    26.    
    27. End Sub
    28.  
    29. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    30.  
    31. CheckValues
    32.  
    33. End Sub
    Last edited by Br1an_g; May 22nd, 2005 at 10:57 AM.
    if you fail to plan, you plan to fail

  3. #3
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: list validation in excel; what if an item in list changes??

    just to add..done some testing and you will need to make sure that the named range and column B range is the same before adding this code or it goes a bit wonky..
    if you fail to plan, you plan to fail

Posting Permissions

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



Click Here to Expand Forum to Full Width