issuing in Comparing Two Columns

Viewed 25

I created a macro that compare two columns in a different worksheets in same workbook and trying highlight the unmatched cells with the green color

but the problem is when I am comparing them only ist row is compared and The next I is not updating their Value. How to overcome this issue.

Sub Abc()

Dim RowUpdate As Double

RowUpdate = 0

    For Each i In sh2.Range("B2:B546")
        For Each j In sh1.Range("E2:E374")
        If i.Cells.Value = j.Cells.Value Then
            'sh1.Cells(i, 5).Interior.ColorIndex = 4
            j.Cells.Interior.ColorIndex = 4
            Else
            j.Cells.Interior.ColorIndex = 6
            'i.Cells.Interior.ColorIndex = vbYellow
            i = i + 1
        'RowUpdate = i + 1
        End If
    Next j
Next i
End sub

The upper function is working fine now when i am comparing two columns in two different worksheets by using CountIF function when (scanerio is i need to check if column E in sheet1 is comparing with column B in sheet2 is same and if column G in sheet1 and Column D in Sheet2 is not same then change color in Orange.

The Data in Case Sensitive.

I write this macro to and didnt get my desired output.

Sub checkOrangeevalues()
RemoveCellFillColor
Set sh1 = Sheets("sheet1")
Set sh2 = Sheets("sheet2")
ColEvalueSh1 = sh1.Range("E" & Rows.Count).End(xlUp).Row 'Column E is documentId sheet1 
ColBvalueSh2 = sh2.Range("B" & Rows.Count).End(xlUp).Row  'count the Records of Column B in Sheets 2
Set myRange = sh2.Range("B2", "B" & ColBvalueSh2)
Set myRange2 = sh2.Range("D2", "D" & ColDvalueSh2)
For i = 2 To ColEvalueSh1 '373
    For j = 2 To ColDvalueSh2 '541
    'white Color That Exist ID doc
     If Application.WorksheetFunction.CountIf(myRange, sh1.Cells(i, 5)) > 0 And Application.WorksheetFunction.CountIf(myRange2, sh1.Cells(i, 7)) = 0 Then
    'If Application.WorksheetFunction.CountIf(sh2.Cells(j, 2), sh1.Cells(i, 5)) = 0 And Application.WorksheetFunction.CountIf(sh2.Cells(j, 4), sh1.Cells(i, 7)) = 0 Then
        sh1.Cells(i, 5).Interior.ColorIndex = 46
        sh1.Cells(i, 6).Interior.ColorIndex = 46
        sh1.Cells(i, 7).Interior.ColorIndex = 46
     'Else
     'If Application.WorksheetFunction.CountIf(myRange, 
       sh1.Cells(i, 5)) 
       > 0 And Application.WorksheetFunction.CountIf(myRange1, 
         sh1.Cells(i, 7)) = 0 Then
        'Else
        'sh1.Cells(i, 5).Interior.ColorIndex = 6 ' 6 is use forYellow color
        'sh1.Cells(i, 6).Interior.ColorIndex = 6
        'End If
        End If
    Next j
Next i

End Sub

0 Answers
Related