Adding Think Border Around Rows With Same Cell Value

Dratchsky

New Member
Joined
Apr 24, 2021
Messages
10
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. Web
Hello,

This is my first post here. I was sure I would be able to find what I was looking for without posting however I didn't.

I would like to add a thick border around rows that share a common value

I have Column B titled Group ID and I would like to have a thick border placed around all the rows that share the same group ID

Below is a photo of the outcome I am looking for

1619273196747.png
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try:
VBA Code:
Sub InsertBorder()
    Application.ScreenUpdating = False
    Dim lRow As Long, i As Long, v As Variant, lVisRow As Long
    lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    v = Range("B2", Range("B" & Rows.Count).End(xlUp)).Value
    With CreateObject("Scripting.Dictionary")
        For i = 1 To UBound(v, 1)
            If Not .Exists(v(i, 1)) Then
                .Add v(i, 1), Nothing
                Range("A1").CurrentRegion.AutoFilter 2, v(i, 1)
                lVisRow = Cells(Rows.Count, "B").End(xlUp).Row
                Range("A1").AutoFilter
                Rows(lVisRow).Borders(xlEdgeBottom).Weight = xlMedium
            End If
        Next i
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you so much!
Try:
VBA Code:
Sub InsertBorder()
    Application.ScreenUpdating = False
    Dim lRow As Long, i As Long, v As Variant, lVisRow As Long
    lRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    v = Range("B2", Range("B" & Rows.Count).End(xlUp)).Value
    With CreateObject("Scripting.Dictionary")
        For i = 1 To UBound(v, 1)
            If Not .Exists(v(i, 1)) Then
                .Add v(i, 1), Nothing
                Range("A1").CurrentRegion.AutoFilter 2, v(i, 1)
                lVisRow = Cells(Rows.Count, "B").End(xlUp).Row
                Range("A1").AutoFilter
                Rows(lVisRow).Borders(xlEdgeBottom).Weight = xlMedium
            End If
        Next i
    End With
    Application.ScreenUpdating = True
End Sub
Works like a gem!
 
Upvote 0
Here is another more compact way to write this macro...
VBA Code:
Sub InsertBorder()
  Dim Cell As Range
  Application.ScreenUpdating = False
  For Each Cell In Range("B2", Cells(Rows.Count, "B").End(xlUp))
    If Cell.Value <> Cell.Offset(1).Value Then Cell.EntireRow.Borders(xlEdgeBottom).Weight = xlMedium
  Next
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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