VBAProIWish
Well-known Member
- Joined
- Jul 6, 2009
- Messages
- 1,027
- Office Version
- 365
- Platform
- Windows
Hello All,
I think this is a pretty simple request. I have many different modules that look for errors in my worksheets and colors any cell red with an error. Note that this is NOT through conditional formatting for many reasons.
The problem that I run into with all my code is that every time a cell is made red, the black font is hard to see against the red cell. I would like to resolve this by changing the font to white anytime a cell is made red.
The code I have that makes cells red doesn't always look the same.
It appears that I have 5 different ways to highlight a cell red
1. - Interior.ColorIndex = 3
2. - Interior.color = RGB(255, 0, 0)
3. - .ColorIndex = 3
4. - Interior.color = vbRed
5. - Interior.color = 255
Here are 5 examples of code that turns my cells red, but keeps the fonts black.
Example 1
Example 2
Example 3
Example 4
Example 5
Note that I only want to have white fonts whose cells were made red through that particular sub/code and can't use conditional formatting due to the way that I manipulate the data.
It needs to be a "solid red cell" with a "solid white font" without being rule-dependent like Conditional Formatting is.
Being only a novice, I won't know what to do if I'm just given a piece of code. If you would please just combine the code with my 5 examples above, that would be great!
Thanks so much!
I think this is a pretty simple request. I have many different modules that look for errors in my worksheets and colors any cell red with an error. Note that this is NOT through conditional formatting for many reasons.
The problem that I run into with all my code is that every time a cell is made red, the black font is hard to see against the red cell. I would like to resolve this by changing the font to white anytime a cell is made red.
The code I have that makes cells red doesn't always look the same.
It appears that I have 5 different ways to highlight a cell red
1. - Interior.ColorIndex = 3
2. - Interior.color = RGB(255, 0, 0)
3. - .ColorIndex = 3
4. - Interior.color = vbRed
5. - Interior.color = 255
Here are 5 examples of code that turns my cells red, but keeps the fonts black.
Example 1
VBA Code:
Select Case LCase(Cells(i, Scol).Value)
Case "need customer number", "need order number": Cells(i, lcol).Interior.ColorIndex = 3 '<<<Cell is Red, but also want to make the font white
End Select
Example 2
VBA Code:
With Cells(i, iCol)
If .Value = "Need customer number" Then .Interior.color = RGB(255, 0, 0) '<<<Cell is Red, but also want to make the font white
Example 3
VBA Code:
With Cells(L4Row, rngGrnd.Column).Interior
.Pattern = xlSolid
If Cells(L4Row, rngGrnd.Column).Value = "" Then
.ColorIndex = 3 '<<<Cell is Red, but also want to make the font white
End if
End with
Example 4
VBA Code:
With ActiveSheet
nCol = Application.Match("Customer Number", .Rows(1), 0)
Dim fnd As Range
Set fnd = Range("1:1").Find("Office", , , xlWhole, , , False, , False)
If Not fnd Is Nothing Then fnd.EntireColumn.SpecialCells(xlBlanks).Interior.color = vbRed'<<<Cell is Red, but also want to make the font white
End With
Example 5
VBA Code:
Do While ActiveCell.Row > 1
If Cells(ActiveCell.Row, totalCol).Value >= 100 _
And Cells(ActiveCell.Row, bigorderCol).Value = "Big Order" Then
Cells(ActiveCell.Row, totalCol).Interior.color = 255'<<<Cell is Red, but also want to make the font white
End If
Note that I only want to have white fonts whose cells were made red through that particular sub/code and can't use conditional formatting due to the way that I manipulate the data.
It needs to be a "solid red cell" with a "solid white font" without being rule-dependent like Conditional Formatting is.
Being only a novice, I won't know what to do if I'm just given a piece of code. If you would please just combine the code with my 5 examples above, that would be great!
Thanks so much!