Dynamic border: Auto-change

jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
834
I'd like a simple macro which automatically changes using Private Sub Worksheet_Change(ByVal Target As Range) when the months in column B do not equal each other.

It needs to thin border from column A to column AT.

Hope that is enough explanation.

Many thanks.

I'd like
Screenshot 2024-03-12 094104.png
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I suggest that you update your forum profile (click your user name at the top right of the forum, then ‘Account details’) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

See if this does what you want.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim a As Variant
  Dim i As Long
 
  If Not Intersect(Target, Columns("B")) Is Nothing Then
    Application.ScreenUpdating = False
    Range("A3:AT" & Rows.Count).Borders.LineStyle = xlNone
    With Range("B3", Range("B" & Rows.Count).End(xlUp))
      a = .Value
      For i = 2 To UBound(a)
        If a(i, 1) <> a(i - 1, 1) Then
          .Cells(i, 0).Resize(, 46).Borders(xlEdgeTop).LineStyle = xlContinuous
        End If
      Next i
    End With
    Application.ScreenUpdating = True
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

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