Excel VBA - FormatConditions problem

B

Byrt Martinez

I'm trying to add Conditional Formatting to cells from VBA, but I can't
figure out how to specify the condition I need. Essentially I want to
check if a cell has any data in it and set the format.

I can't seem to figure out how to specify a null string argument in the
Formula1 parameter. Normally, in the Excel menus, when setting
Conditional Formatting, I can set this to ="", but this won't work in
code. I've tried numerous variations, but no luck. I've tried, "="""",
Null, Empty, vbNullString, but the function won't accept it. :mad:

Any clues? I'm baffled.

Thanks!
Byrt
 
G

Guest

Byrt

A couple of options:
Range("b3").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$B$3="""""
Selection.FormatConditions(1).Interior.ColorIndex = 38
Range("b5").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=isblank(b5)"
Selection.FormatConditions(1).Interior.ColorIndex = 45

The first one will set B3 and the second one will set B5

Tony


----- Byrt Martinez > wrote: -----

I'm trying to add Conditional Formatting to cells from VBA, but I can't
figure out how to specify the condition I need. Essentially I want to
check if a cell has any data in it and set the format.

I can't seem to figure out how to specify a null string argument in the
Formula1 parameter. Normally, in the Excel menus, when setting
Conditional Formatting, I can set this to ="", but this won't work in
code. I've tried numerous variations, but no luck. I've tried, "="""",
Null, Empty, vbNullString, but the function won't accept it. :mad:

Any clues? I'm baffled.

Thanks!
Byrt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top