Conditionally formatting cells if their value equals any value of another column

后端 未结 6 1573
温柔的废话
温柔的废话 2020-12-29 07:50

I have data in the A and B columns. B column\'s data is mostly duplicates of A\'s data, but not always. For example:

6条回答
  •  遥遥无期
    2020-12-29 08:14

    All you need to do for that is a simple loop.
    This doesn't handle testing for lower case, upper-case mismatch. If this isn't exactly what you are looking for, comment, and I can revise.

    If you are planning to learn VBA. This is a great start.

    TESTED:

    Sub MatchAndColor()
    
    Dim lastRow As Long
    Dim sheetName As String
    
        sheetName = "Sheet1"            'Insert your sheet name here
        lastRow = Sheets(sheetName).Range("A" & Rows.Count).End(xlUp).Row
    
        For lRow = 2 To lastRow         'Loop through all rows
    
            If Sheets(sheetName).Cells(lRow, "A") = Sheets(sheetName).Cells(lRow, "B") Then
                Sheets(sheetName).Cells(lRow, "A").Interior.ColorIndex = 3  'Set Color to RED
            End If
    
        Next lRow
    
    End Sub
    

    EXAMPLE

提交回复
热议问题