VBA code to add thick border around group of rows containing a bolded cell.

Curtisyoung78

New Member
Joined
Jun 19, 2017
Messages
25
Once again I need your help. I am looking for a code to find rows that have atleast one bolded cell then place a thick border around that row and if there are consecutive rows containing bolded cells add a thick border around group of cells. the range is A12 to column R and the bottom row used. I am trying to frame the groups of rows containing bolded cells wether its just one or multiple rows consecutively, the one row to have its own border and a group of multiple consecutive rows to get another border.

example. Row 13 has a bolded cell (col range A to R) and also rows 16 through (and including) row 24 all contain atleast one bolded cell each, then bold around A13:R13 (thick border around row and not all cells)and also a thick border around A16:R24 (one thick border around group of rows and not around individual rows or cells).

Thanks for your help in advance.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG01Aug49
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] nRng [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
[COLOR="Navy"]For[/COLOR] Ac = 0 To 18
    [COLOR="Navy"]If[/COLOR] Dn.Offset(, Ac).Font.Bold [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]If[/COLOR] nRng [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
            [COLOR="Navy"]Set[/COLOR] nRng = Cells(Dn.Row, 1).Resize(, 18)
        [COLOR="Navy"]Else[/COLOR]
            [COLOR="Navy"]Set[/COLOR] nRng = Union(nRng, Cells(Dn.Row, 1).Resize(, 18))
        [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]Exit[/COLOR] For
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR] Ac
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] nRng.Areas
    Dn.BorderAround ColorIndex:=1, Weight:=xlThick
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Here is another macro that you can try...
Code:
[table="width: 500"]
[tr]
	[td]Sub PutBordersAroundCells()
  Dim R As Long, UnusedColumn As Long, LastRow As Long, Ar As Range
  UnusedColumn = Cells.Find("*", , xlFormulas, , xlByColumns, xlPrevious).Column + 1
  LastRow = Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
  For R = 12 To LastRow
    If Rows(R).Font.Bold = True Or IsNull(Rows(R).Font.Bold) Then Cells(R, UnusedColumn).Value = "X"
  Next
  On Error GoTo NoBoldCells
  For Each Ar In Intersect(Columns("A:R"), Columns(UnusedColumn).SpecialCells(xlConstants).EntireRow).Areas
    Ar.BorderAround xlContinuous, xlThick
  Next
NoBoldCells:
  Columns(UnusedColumn).Clear
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Worked perfectly, exactly what I was looking for, thanks very much MikeG.
Try this:-
Code:
[COLOR=Navy]Sub[/COLOR] MG01Aug49
[COLOR=Navy]Dim[/COLOR] Rng [COLOR=Navy]As[/COLOR] Range, Dn [COLOR=Navy]As[/COLOR] Range, Ac [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long,[/COLOR] nRng [COLOR=Navy]As[/COLOR] Range
[COLOR=Navy]Set[/COLOR] Rng = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] Dn [COLOR=Navy]In[/COLOR] Rng
[COLOR=Navy]For[/COLOR] Ac = 0 To 18
    [COLOR=Navy]If[/COLOR] Dn.Offset(, Ac).Font.Bold [COLOR=Navy]Then[/COLOR]
        [COLOR=Navy]If[/COLOR] nRng [COLOR=Navy]Is[/COLOR] Nothing [COLOR=Navy]Then[/COLOR]
            [COLOR=Navy]Set[/COLOR] nRng = Cells(Dn.Row, 1).Resize(, 18)
        [COLOR=Navy]Else[/COLOR]
            [COLOR=Navy]Set[/COLOR] nRng = Union(nRng, Cells(Dn.Row, 1).Resize(, 18))
        [COLOR=Navy]End[/COLOR] If
    [COLOR=Navy]Exit[/COLOR] For
    [COLOR=Navy]End[/COLOR] If
[COLOR=Navy]Next[/COLOR] Ac
[COLOR=Navy]Next[/COLOR] Dn
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] Dn [COLOR=Navy]In[/COLOR] nRng.Areas
    Dn.BorderAround ColorIndex:=1, Weight:=xlThick
[COLOR=Navy]Next[/COLOR] Dn
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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