Excel VBA | Formatting (Empty Cells = Yellow, Change Font Color)

SoniboiTM

New Member
Joined
Jul 25, 2020
Messages
38
Office Version
  1. 2019
Platform
  1. Windows
  2. Web
Additional to my previous post:

Trying my best to format my table but can't figure out how.

Code:
   Dim UsdCols As Long
    
   UsdCols = Cells(6, Columns.Count).End(xlToLeft).Column
   With Range("P6:P500")
      .FormatConditions.Delete
      .FormatConditions.Add Type:=xlExpression, Formula1:= _
         "=AND($P6<>"""",$P6<$Q6)"
      With .FormatConditions(.FormatConditions.Count)
         .SetFirstPriority
         .Font.Color = vbRed
      End With
      .FormatConditions.Add Type:=xlExpression, Formula1:= _
         "=AND($P6<>"""",$P6>$Q6)"
      With .FormatConditions(.FormatConditions.Count)
         .SetFirstPriority
         '.Font.Color = vbGreen
         .Font.ColorIndex = 10
      End With
      .FormatConditions.Add Type:=xlExpression, Formula1:= _
         "=AND($P6<>"""",$P6=$Q6)"
      With .FormatConditions(.FormatConditions.Count)
         .SetFirstPriority
         .Font.Color = vbBlue
      End With
   End With
   With Range("Q6", Cells(500, UsdCols))
      .FormatConditions.Delete
      
      'Empty cells = Yellow
      .FormatConditions.Add Type:=xlExpression, Formula1:= _
         "=$P6="""""
      With .FormatConditions(.FormatConditions.Count)
         .SetFirstPriority
         '.Font.Color = vbGreen
         .Interior.ColorIndex = 19
      End With
      
      .FormatConditions.Add Type:=xlExpression, Formula1:= _
         "=AND(Q6<>"""",Q6>P6)"
      With .FormatConditions(.FormatConditions.Count)
         .SetFirstPriority
         '.Font.Color = vbGreen
         .Font.ColorIndex = 10
      End With
      .FormatConditions.Add Type:=xlExpression, Formula1:= _
         "=AND(Q6<>"""",Q6<P6)"
      With .FormatConditions(.FormatConditions.Count)
         .SetFirstPriority
         .Font.Color = vbRed
      End With
      .FormatConditions.Add Type:=xlExpression, Formula1:= _
         "=AND(Q6<>"""",Q6=P6)"
      With .FormatConditions(.FormatConditions.Count)
         .SetFirstPriority
         .Font.Color = vbBlue
      End With
   End With

Condition (Stock Market data):
- From "P" column onward:
-- Empty cells = yellow fill
-- If previous price < closing price --> closing price font is green
-- If the previous price > closing price --> closing price font is red
-- If the previous price = closing price --> closing price font is blue

Help me, please ...
I attached a screenshot for clarification.
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    179.1 KB · Views: 21

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,214,976
Messages
6,122,539
Members
449,088
Latest member
RandomExceller01

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