Conditional Formatting VBA Question

ststern45

Well-known Member
Joined
Sep 17, 2005
Messages
965
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hello everyone,

I have a question about how to use VBA to format a cell based on another range of cells.

For example using the code at the very bottom is pretty close to what I was looking for but need the following:

I have a range of cell U3:FG145 that is either a blank cell or not blank (not blank cell(s) contain a letter and number such as F6)

The second range of data is located in cell range N20:N4219

So this is what I would like to accomplish:

1>Highlight the cells in range U3:FG145 that are blank code: > c.Interior.Color = RGB(0, 0, 0) 'Color Black

2>Highlight the cells in range U3:FG145 that contain the data from cell range N20:N4219 code: > c.Interior.Color = RGB(146, 208, 80) 'Color Light Green

Thanks in advance!!

For Each c In Range("U3:FG145").Cells

If c.Value = "" Then
c.Interior.Color = RGB(0, 0, 0) 'Color Black
Else
c.Interior.Color = xlNone

End If

Next c
 
Last edited:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
For number 1....

Code:
Sub FillBlk()
Range("U3:FG145").Interior.ColorIndex = xlNone
Range("U3:FG145").SpecialCells(4).Interior.Color = RGB(0, 0, 0)
End Sub
 
Upvote 0
How about
Code:
   Dim Cl As Range
   Dim Var As Variant
   For Each Cl In Range("U3:FG145")
      If Cl.Value = "" Then
         Cl.Interior.Color = RGB(0, 0, 0) 'Color Black
      Else
         Var = Application.Match(Cl.Value, Range("N20:N4219"), 0)
         If Not IsError(Var) Then
            Cl.Interior.Color = RGB(146, 208, 80)
         Else
            Cl.Interior.Color = xlNone
         End If
      End If
   Next Cl
 
Last edited:
Upvote 0
OK Super!!

Works great.

Thanks for all your help!!
 
Upvote 0
Just a quick question.

How would I apply Bold to these cells?

Thanks
 
Upvote 0

Forum statistics

Threads
1,215,756
Messages
6,126,692
Members
449,330
Latest member
ThatGuyCap

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