Return digit that does not exist in a cell

Closed
Jean - May 23, 2010 at 06:44 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - May 25, 2010 at 04:58 PM
Good Day all,

Cell A2 is 012 in text format. Cell B2 is 0821 in text format too.
Is there a function that can check value in cell B2 against cell A2 and return the digit that does not exist in cell A2?
For example, cell B2 is 0821, when checked agained cell A2's value of 012, it will return digit 8 which does not exist in A2.


3 responses

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
May 23, 2010 at 09:13 AM
what would be the maximum length of values in either cells
0
column A will have 3-digit numbers e.g 012, column B will have 4-digit numbers e.g 2180. I would like column C to return the missing digit or in case there is no missing digit, to return the smallest digit that match the 4-digit numbers in column A.
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
May 25, 2010 at 04:58 PM
try this

Function myCompare(compareThis As String, compareAgainst As String)
Dim StringAbsent As String
Dim MaxAbsent As String
Dim MinAbsent As String
Dim CheckThis As String

Dim iCounter As Long

    MaxAbsent = ""
    MinAbsent = ""
    StringAbsent = ""
    
    For ichar = 1 To Len(compareThis)
        
        CheckThis = CStr(Mid(compareThis, ichar, 1))
        present = CStr(InStr(1, CStr(compareAgainst), CheckThis))
        
        If present > 0 Then
                
            If (CheckThis > MaxAbsent) Then MaxAbsent = CheckThis
            If (CheckThis < MinAbsent) Then MinAbsent = CheckThis
            If (MinAbsent = "") Then MinAbsent = CheckThis
        Else
            
            StringAbsent = StringAbsent & CheckThis
        
        End If
        
        
    Next ichar

    If StringAbsent = "" Then
        myCompare = MinAbsent
    Else
        myCompare = StringAbsent
    End If
    
End Function
0