• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Check 1st scan # is tally with 2nd scan number

Choong

New Member
i would like to know what is the code to be used if for example there is 2 input scan number. And there is a button to compare both scanned number is tally then the result will be CORRECT and GREEN else it will be WRONG and RED. Can anyone help me?
The scanned number is just accept numberic only
 

Attachments

Hi Choong -

As per the sample file..both numbers do not match and the result in D4 says "pass" & highlights the cell in green.

I am assuming that is wrong..

Code:
Sub test()

 Dim l_Row As Long
    Dim cell As Range
           
    Sheets("Sheet1").Select
    
    l_Row = Cells(Rows.Count, "B").End(xlUp).Row
    
    For Each cell In Range("B4:B" & l_Row)
    
        If cell.Value = cell.Offset(, 1) Then
            
            With cell.Offset(, 2)
                
                .Value = "Correct"
                .Interior.Color = RGB(169, 209, 141)
            
            End With
        
        Else
        
            With cell.Offset(, 2)
                
                .Value = "Wrong"
                .Interior.Color = RGB(191, 44, 19)
            
            End With
            
        End If
    
    Next cell

End Sub

Also attached is for the ref..
 

Attachments

Hi Choong -

As per the sample file..both numbers do not match and the result in D4 says "pass" & highlights the cell in green.

I am assuming that is wrong..

Code:
Sub test()

Dim l_Row As Long
    Dim cell As Range
          
    Sheets("Sheet1").Select
   
    l_Row = Cells(Rows.Count, "B").End(xlUp).Row
   
    For Each cell In Range("B4:B" & l_Row)
   
        If cell.Value = cell.Offset(, 1) Then
           
            With cell.Offset(, 2)
               
                .Value = "Correct"
                .Interior.Color = RGB(169, 209, 141)
           
            End With
       
        Else
       
            With cell.Offset(, 2)
               
                .Value = "Wrong"
                .Interior.Color = RGB(191, 44, 19)
           
            End With
           
        End If
   
    Next cell

End Sub

Also attached is for the ref..


Asheesh,

Thanks...You helped me solved a problem. Thank you very much...
 
Hi Asheesh,
How about if i would like to check for the whole list. Means that if i scan both serial number till 300 records then only press the compare button.
 
Back
Top