VBA Excel - Checking Text Similarity in Same Column

If you are OK with a thin black border, then conditional formatting will work. If you really want a thick black border, you will need VBA event code, since you cannot modify the thickness of a border in the conditional formatting border property.

To enter this event-triggered Macro, right click on the sheet tab. Select "View Code" from the right-click drop-down menu. Then paste the code below into the window that opens.

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim dataRange As Range
    Dim v As Variant, I As Long
    
Set dataRange = Range(Cells(2, 2), Cells(100, 10)) 'change as needed
If Not Intersect(Target, dataRange) Is Nothing Then
    With dataRange
        v = .Columns(9)
        For I = 1 To UBound(v) - 1
            If v(I, 1) <> v(I + 1, 1) Then
                With .Rows(I).Borders(xlEdgeBottom)
                    .LineStyle = xlContinuous
                    .Color = vbBlack
                    .Weight = xlThick
                End With
            Else
                .Rows(I).Borders(xlEdgeBottom).LineStyle = xlNone 'or whatever you want for the default border
            End If
        Next I
    End With
End If
End Sub

Edit: to have a stand-alone and not an event-triggered macro
enter into a regular module
you can then call it from another macro, or trigger it with a button, or start it manually

Option Explicit
Sub LineIT()
    Dim WS As Worksheet
    Dim dataRange As Range
    Dim v As Variant, I As Long
    
Set WS = ThisWorkbook.Worksheets("Sheet4") 'or whatever workbook and worksheet the table you which to process is located

With WS
    Set dataRange = Range(.Cells(2, 1), Cells(.Rows.Count, 10).End(xlUp)) 'change as needed
    With dataRange
        v = .Columns(10)
        For I = 1 To UBound(v) - 1
            If v(I, 1) <> v(I + 1, 1) Then
                With .Rows(I).Borders(xlEdgeBottom)
                    .LineStyle = xlContinuous
                    .Color = vbBlack
                    .Weight = xlThick
                End With
            Else
                .Rows(I).Borders(xlEdgeBottom).LineStyle = xlNone 'or whatever you want for the default border
            End If
        Next I
    End With
End With
End Sub

enter image description here


This is easily accomplished with conditional formatting.

  1. Make the active cell J2
  2. Open up the conditional format dialog box
  3. Select Use Formula for Conditional Formatting
  4. Type in the formula =$J2<>$J1 and set the border as you like
  5. Adjust the Applies To cells to make the underline go to the cells you want

Excel Conditional Formatting