VBA and FORMULA: Count Red Bold Text from Conditional Formatting

chrono2483

Board Regular
Joined
Aug 23, 2014
Messages
164
Office Version
  1. 2016
Hello Everyone!

I've tried to find the answer to this online and have tried many VBA/formula to achieve what I need to do, with no success.

I have a set of data that i've applied conditional formatting. I've used the Top 20% and Bottom 20% to highlight the applicable cells as RED BOLD text. Outside of the conditional formatting, I already have these cells colored. So I am looking to only apply a formula that counts the # of cells that have the RED BOLD text applied by conditional formatting.

Sample:

ABCD
120020%50100
24915%49101
3250.1%8820
41490.0%10012

<tbody>
</tbody>

Row 1 = 1
Row 2 = 1
Row 3 = 2
Row 4 = 0


I hope this makes sense. Using a countif based on the same conditions as the conditional formatting is not an options. I am looking for a VBA code and/or another formula that will achieve the same outcome.

Thank you.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
This should do it.

Code:
Function BoldRed(r As Range) As Long
Dim Cnt As Long
Dim cel As Range
For Each cel In r
    If cel.Font.Color = vbRed And cel.Font.Bold = True Then Cnt = Cnt + 1
Next cel
BoldRed = Cnt
End Function

Then your formula would take the entire range that you're working with as its only argument, e.g. =BoldRed(A1:D4)
 
Upvote 0
Here is a macro that you can use (it puts the output two columns over from the last data column)...
Code:
[table="width: 500"]
[tr]
	[td]Sub CFRedBoldCounts()
  Dim R As Long, C As Long, StartRow As Long, StartCol As Long, LastRow As Long, LastCol As Long, RowCount As Long
  StartRow = 1
  StartCol = 1
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
  For R = StartRow To LastRow
    RowCount = 0
    For C = StartCol To LastCol
      If Cells(R, C).DisplayFormat.Font.Bold And Cells(R, C).DisplayFormat.Font.Color = vbRed Then RowCount = RowCount + 1
    Next
    Cells(R, LastCol + 2).Value = RowCount
  Next
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
This should do it.

Code:
Function BoldRed(r As Range) As Long
Dim Cnt As Long
Dim cel As Range
For Each cel In r
    If cel.Font.Color = vbRed And cel.Font.Bold = True Then Cnt = Cnt + 1
Next cel
BoldRed = Cnt
End Function

Then your formula would take the entire range that you're working with as its only argument, e.g. =BoldRed(A1:D4)

Thank you lrobbo314 - your approach works when manually making text BOLD and RED. However it does not seem to pick up those that were formatting through conditional formatting. Could I be doing something wrong?
 
Upvote 0
Here is a macro that you can use (it puts the output two columns over from the last data column)...
Code:
[TABLE="width: 500"]
<tbody>[TR]
[TD]Sub CFRedBoldCounts()
  Dim R As Long, C As Long, StartRow As Long, StartCol As Long, LastRow As Long, LastCol As Long, RowCount As Long
  StartRow = 1
  StartCol = 1
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
  For R = StartRow To LastRow
    RowCount = 0
    For C = StartCol To LastCol
      If Cells(R, C).DisplayFormat.Font.Bold And Cells(R, C).DisplayFormat.Font.Color = vbRed Then RowCount = RowCount + 1
    Next
    Cells(R, LastCol + 2).Value = RowCount
  Next
End Sub[/TD]
[/TR]
</tbody>[/TABLE]

Amazing! Thank you Rick - it worked! :)
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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