Macro to bold, highlight & change font color of certain cells in a column

afterdinnerspeaker

Board Regular
Joined
Jan 10, 2019
Messages
70
MACRO TO BOLD, HIGHLIGHT & CHANGE FONT COLOR OF CERTAIN CELLS IN A COLUMN


I’m embarrassed to say how long I’ve been searching for an answer to the following problem:

The last column(“H”) on my spreadsheet contains the numeric totals of expenses in each row.
There are also spaces between some rows (blank cells).

Cells in that column are either zeros (0.00) or contain a number greater than zero or they’re blank.

My purpose is to find these specific totals to BOLD, highlight & change font color.



COLUMN “H”

Balance

0.00

0.00
6,638.84
15,250.15
43,193.79 ß--------


0.00
4,800.00 ß--------

0.00

0.00

0.00

0.00


0.00


Many thanks in advance for any help you can give me!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Welcome to the MrExcel board!

Try this in a copy of your workbook. It assumes that those values in column H are the results of formulas.
Code:
Sub Format_Totals_v1()
  Dim rA As Range
  
  For Each rA In Range("H2", Range("H" & Rows.Count).End(xlUp)).SpecialCells(xlFormulas, xlNumbers).Areas
    With rA.Cells(rA.Cells.Count)
      If .Value > 0 Then
        With .Font
          .Bold = True
          .Color = vbRed
        End With
        .Interior.Color = vbYellow
      End If
    End With
  Next rA
End Sub


Hi Peter!

I just wanted to say thank you again for your help almost 2 months ago.

Initially, with your code, I was getting the dreaded "Run-time error '1004' No cells were found".

In the meantime, Rick suggested his own version which worked well at the beginning but had a tiny glitch which didn't show up until recently.

However, Rick had suggested earlier that your macro, with a slight change (xlFormulas to xlConstants) would work as well.

Just today, I returned to your code (with that change made) and it works like a dream without the glitches!

You both offer such a terrific service and I'm very grateful.

Cheers,

Jerry
 
Upvote 0
Welcome to the MrExcel board!

Try this in a copy of your workbook. It assumes that those values in column H are the results of formulas.
Code:
Sub Format_Totals_v1()
  Dim rA As Range
  
  For Each rA In Range("H2", Range("H" & Rows.Count).End(xlUp)).SpecialCells(xlFormulas, xlNumbers).Areas
    With rA.Cells(rA.Cells.Count)
      If .Value > 0 Then
        With .Font
          .Bold = True
          .Color = vbRed
        End With
        .Interior.Color = vbYellow
      End If
    End With
  Next rA
End Sub

Hi Peter!

As per suggestion from Rick a while back, I simply changed SpecialCells(xlFormulas, xlNumbers) to SpecialCells(xlConstants, xlNumbers) to make your code work when values in column H are constants.

Just wondering if there's any way to alter the code if column H has a mix of both "results of formulas" (as in your original code) and "constants"?

Many thanks,

Jerry
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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