VBA Add Bottom Border at Change in Value in Column Help

sph523

New Member
Joined
Dec 14, 2022
Messages
3
Office Version
  1. 2021
Platform
  1. Windows
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
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
How about
VBA Code:
If Range("E" & i).Value <> Range("E" & i + 1).Value Then
 
Upvote 0
Solution
How about
VBA Code:
If Range("E" & i).Value <> Range("E" & i + 1).Value Then
I'm an idiot. That's what it originally was and I was fiddling with it before posting this.
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,614
Messages
6,125,843
Members
449,266
Latest member
davinroach

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top