Hello and thank you in advance for your help! I'm trying to create an Excel VBA macro that changes the color of NUMBERS based on criteria, but does NOT change the color of TEXT. Specifically, I wanted to change only cells with NUMBERS, whether they are hardcoded or the result of a formula, based on the following criteria:
Any help you could provide in updating this code so it only changes the colors of numbers, and not text or combination of text and numbers within a cell, would be really helpful. Thank you!
- Hardcoded: BLUE
- Link to another tab within the same workbook: GREEN
- Link to the same tab within the same workbook: MAROON
- Link to another workbook file: RED
- Formula: BLACK
VBA Code:
Sub Finance_Model_Color_Coder()
Dim cell As Range
Sheet1.UsedRange.SpecialCells(xlCellTypeConstants).Font.Color = RGB(0, 0, 255) 'blue
For Each cell In Sheet1.UsedRange.SpecialCells(xlCellTypeFormulas)
If InStr(1, cell.Formula, "!") > 0 Then cell.Font.Color = RGB(50, 205, 50) 'lime green
If InStr(1, cell.Formula, "!") = 0 Then cell.Font.Color = RGB(128, 0, 0) 'maroon
If InStr(1, cell.Formula, "!") = 0 And InStr(1, cell.Formula, "(") > 0 Then cell.Font.Color = RGB(0, 0, 0) 'black
If InStr(1, cell.Formula, "[") > 0 Then cell.Font.Color = RGB(255, 0, 0) 'red
Next cell
End Sub
Any help you could provide in updating this code so it only changes the colors of numbers, and not text or combination of text and numbers within a cell, would be really helpful. Thank you!