Results 1 to 7 of 7

Unique Values

Threaded View

  1. #1
    Registered User
    Join Date
    11-22-2008
    Location
    Brisbane, Australia
    MS-Off Ver
    2003
    Posts
    23

    Unique Values

    Hey guys and gals,

    I need an error box to come up when a value is the same as a value that is already entered.

    Column D has Names lets say Bill, Bob, Jack
    Column J has Names lets say Jerry, Shelly, Joe

    Now if I enter Bill into either column again I want an error box come up and tell let me know that value already exists and I want it to simply clear that cell.

    I have adapted this code, but it only works with one column how do I make it work with the other column.

    I don't want it to check the columns in between.

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    
        Dim LLoop As Integer
        Dim LTestLoop As Integer
        
        Dim Lrows As Integer
        Dim LRange As String
        Dim LChangedValue As String
        Dim LTestValue As String
        
        'Test first 200 rows in spreadsheet for uniqueness
        Lrows = 200
        LLoop = 2
        
        'Check first 200 rows in spreadsheet
        While LLoop <= Lrows
            LChangedValue = "D" & CStr(LLoop)
            
            If Not Intersect(Range(LChangedValue), Target) Is Nothing Then
                If Len(Range(LChangedValue).Value) > 0 Then
                
                    'Test each value for uniqueness
                    LTestLoop = 2
                    While LTestLoop <= Lrows
                        If LLoop <> LTestLoop Then
                            LTestValue = "D" & CStr(LTestLoop)
                            'Value has been duplicated in another cell
                            If Range(LChangedValue).Value = Range(LTestValue).Value Then
                                'Clear Contents
                                Range(LChangedValue).ClearContents
                                MsgBox Range(LChangedValue).Value & " already exists in cell D" & LTestLoop
                                Exit Sub
                            Else
                                Range(LChangedValue).Interior.ColorIndex = xlNone
                            End If
                                
                        End If
                        
                        LTestLoop = LTestLoop + 1
                    Wend
                    
                End If
            End If
            
            LLoop = LLoop + 1
        Wend
        
    End Sub
    Thanks
    Steven
    Last edited by merilvingian; 01-15-2009 at 12:14 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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