1

Image 1

Image 2

I am trying to check for text similarity for the text in the "Line-Side Loc" in Column J. If the text in column J isn't the same, I would like a thick bottom border applied from columns A-J to annunciate the difference. If the text is the same, I would like it to be a thin line. Image 1 is what it looks like currently when the macro ends. Ideally, it would look like Image 2.

This is my code and where I would like to insert the new code to add the thick lines Code

I do not know how to write this code. Any help would be appreciated.

Thanks!

Currently, this is what is happening. With the code I have below. Current Outcome Current Code

4
  • 1
    Both images look the same to me. Not sure but it looks like conditional formatting may do what you want. Can you please edit your question to clarify things? Bear in mind we don't have access to your spreadsheet. Jul 12, 2021 at 22:04
  • isn't the same as what? And you still haven,t explained the difference between the two images. Jul 12, 2021 at 23:40
  • He wants to have a black border anytime the text above the cell in J column changes. It is easily done with conditional formatting.
    – wbeard52
    Jul 13, 2021 at 0:09
  • You can get a thin black border with conditional formatting, but if you really want a thick black border, you will need VBA event code. Jul 13, 2021 at 1:27

2 Answers 2

1

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

1
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – DavidPostill
    Jul 15, 2021 at 6:53
1

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

0

You must log in to answer this question.