Mismatch between two columns

     

  • Based on first column, compare second
  • Serial Order doesn't change between 2 columns
  •  

    Private Sub CommandButton1_Click()
    Dim fc As Integer, fr As Integer
    fc = 1
    fr = 1
    Dim lr As Integer
    lr = Range(Cells(fr, fc), Cells(fr, fc).End(xlDown)).Rows.Count
    Dim sc As Integer, sr As Integer
    sc = 3: sr = 1
    slr = Range(Cells(sr, sc), Cells(sr, sc).End(xlDown)).Rows.Count
    For i = fr To lr
    If Cells(sr, sc) <> Cells(fr, fc) Then
    Cells(fr, fc).Interior.ColorIndex = 3
    End If
    fr = fr + 1
    sr = sr + 1
    Next
    End Sub

     

    Comparision based on second column

     

  • Highlight in second column
  •  

    Private Sub CommandButton1_Click()
    Dim fc As Integer, fr As Integer
    fc = 1
    fr = 1
    Dim lr As Integer
    lr = Range(Cells(fr, fc), Cells(fr, fc).End(xlDown)).Rows.Count
    Dim sc As Integer, sr As Integer
    sc = 3: sr = 1
    slr = Range(Cells(sr, sc), Cells(sr, sc).End(xlDown)).Rows.Count
    For i = fr To lr
    If Cells(fr, fc) <> Cells(sr, sc) Then
    Cells(sr, sc).Interior.ColorIndex = 3
    End If
    fr = fr + 1
    sr = sr + 1
    Next
    End Sub

     

     

    Comparision between two sheets

     

  • Highlights value in 3rd sheet, based on 2nd sheet
  • Private Sub CommandButton1_Click()
    Dim fc As Integer, fr As Integer
    fc = 1
    fr = 1
    Dim lr As Integer
    lr = Sheets("sheet2").Range(Cells(fr, fc), Cells(fr, fc).End(xlDown)).Rows.Count
    Dim sc As Integer, sr As Integer
    sc = 1: sr = 1
    For i = fr To lr
    If Sheets("sheet2").Cells(fr, fc) <> Sheets("sheet3").Cells(sr, sc) Then
    Sheets("sheet3").Cells(sr, sc).Interior.ColorIndex = 3
    End If
    fr = fr + 1
    sr = sr + 1
    Next
    End Sub

     

     

     

     

    Comparision between two Columns - FIND function

     

    Sub Comparision_Between_Two_Columns()
    Dim Sh As Worksheet
    Set Sh = ThisWorkbook.Sheets("V-Lookup")
    Max = Sh.Range("A" & Rows.Count).End(xlUp).Row
    For i = 2 To Max
    Set v = Sh.Range("B2:B" & Max).Find(what:=Sh.Cells(i, 1).Value, LookIn:=xlValues)
    If Not v Is Nothing Then
    v.Select
    r = ActiveCell.Row
    Cells(r, 3).Value = Cells(i, 1).Row
    ElseIf v Is Nothing Then
    Cells(i, 3).Value = "Data Not Available"
    End If
    Next
    End Sub