VBA color negative numbers red within range

jamada

Active Member
Joined
Mar 23, 2006
Messages
323
I've seen many variations but just looing for simple code, without using conditional formatting. Any suggestions to correct the following to run?

Thank you

With Range ("C3:AA27")
For Each cell In Range
If cell.Value < 0 Then
With Selection.Font
.Name = "Calibri"
.FontStyle = "Bold"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.Color = 255
.TintAndShade = 0
.ThemeFont = xlThemeFontMinor

End With
End If
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Yes, change this part:
Code:
[COLOR=#333333]If cell.Value < 0 Then[/COLOR]
[COLOR=#333333]With Selection.Font[/COLOR]
to this:
Code:
[COLOR=#333333]If cell.Value < 0 Then[/COLOR]
[COLOR=#333333]With [/COLOR][B][COLOR=#ff0000]cell[/COLOR][/B][COLOR=#333333].Font[/COLOR]
 
Upvote 0
You are welcome!

The key think to remember that Selection will be the selected cells when you code first starts (since your code is not selecting anything).
You are looping through your range using "cell" as the individual range object, so that is what you want to reference in your formatting code.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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