Hello all,
I'm hoping you can help me find my error in my VBA code. I have it sort column E then add a bottom border to the rows where the value in column E changes. Unfortunately, it seems to work just fine until we get out of the single digits, from there it only looks at the first digit so it adds the border when the 10s turn to 20s and 20s to 30s. I have the code below. It was stolen from some forum and Frankenstein'd together for my purposes so I'm sure I messed up somewhere in there.
Sub AddBorder()
Range("A5:P51").Sort Key1:=Range("E5"), Order1:=xlAscending, Header:=xlNo
Dim i As Long
For i = 5 To Range("P" & Rows.Count).End(xlUp).Row
If Left(Range("E" & i).Value, 1) <> Left(Range("E" & i + 1).Value, 10) Then
Range("A" & i).Resize(, 16).Borders(xlEdgeBottom).Weight = xlThick
End If
Next i
End Sub
I'm hoping you can help me find my error in my VBA code. I have it sort column E then add a bottom border to the rows where the value in column E changes. Unfortunately, it seems to work just fine until we get out of the single digits, from there it only looks at the first digit so it adds the border when the 10s turn to 20s and 20s to 30s. I have the code below. It was stolen from some forum and Frankenstein'd together for my purposes so I'm sure I messed up somewhere in there.
Sub AddBorder()
Range("A5:P51").Sort Key1:=Range("E5"), Order1:=xlAscending, Header:=xlNo
Dim i As Long
For i = 5 To Range("P" & Rows.Count).End(xlUp).Row
If Left(Range("E" & i).Value, 1) <> Left(Range("E" & i + 1).Value, 10) Then
Range("A" & i).Resize(, 16).Borders(xlEdgeBottom).Weight = xlThick
End If
Next i
End Sub