VBA Conditional Format. Formula Array

Tigs81

Board Regular
Joined
Mar 10, 2011
Messages
70
Hi

I have an issue with the conditional format when i manually enter the an array formula into the formula field in the conditional format window it works.
eg =IF(OR(IF(E4:E6<NOW(),IF(E4:E6="""",FALSE,TRUE),FALSE))=TRUE,TRUE,FALSE)"

If i enter the same array formula via VBA it doesnt work until i manual open the conditional format window and click ok to close it.
eg Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=IF(OR(IF(E4:E6<NOW(),IF(E4:E6="""",FALSE,TRUE),FALSE))=TRUE,TRUE,FALSE)"

if i do the same thing with this non array formula it works fine both via vba and manually.
=IF(SUM(G4:G6)>3,TRUE,FALSE)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
<o:p>I have read somewhere that conditional formatting always treats the formulas as a array formula but it doesnt seem to do that when i have added it in via VBA.</o:p>
<o:p></o:p>
<o:p>Any Idea's?</o:p>
<o:p></o:p>
<o:p>Thanks</o:p>
<o:p>tigs</o:p>
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Can't see your formulas ... surround them with code tags.
 
Upvote 0
sorry i didnt realize.

I have an issue with the conditional format when i manually enter the an array formula into the formula field in the conditional format window it works.
eg
Code:
=IF(SUM(G1:G10*H1:H10)>3,TRUE,FALSE)
<NOW(),IF(E4:E6="""",FALSE,TRUE),FALSE))=TRUE,TRUE,FALSE)"< font>
If i enter the same array formula via VBA it doesnt work until i manual open the conditional format window and click ok to close it.
eg
Code:
<?XML:NAMESPACE PREFIX = NOW(),IF(E4 /><NOW(),IF(E4:E6="""",FALSE,TRUE),FALSE))=TRUE,TRUE,FALSE)"< font>Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=IF(SUM(G1:G10*H1:H10)>3,TRUE,FALSE)"</NOW(),IF(E4:E6="""",FALSE,TRUE),FALSE))=TRUE,TRUE,FALSE)"<>

</NOW(),IF(E4:E6="""",FALSE,TRUE),FALSE))=TRUE,TRUE,FALSE)"<><NOW(),IF(E4:E6="""",FALSE,TRUE),FALSE))=TRUE,TRUE,FALSE)"< font><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>I have also noticed that when entering the array formula via VBA it does actually evaluate the first row eg G1*H1>3 but does do the other rows until the conditional format window is opened and ok is clicked to close it.

<NOW(),IF(E4:E6="""",FALSE,TRUE),FALSE))=TRUE,TRUE,FALSE)"< font>
if i do the same thing with this non array formula it works fine both via vba and manually.
=IF(SUM(G4:G6)>3,TRUE,FALSE)<o:p></o:p>
<o:p></o:p>
<o:p>I have read somewhere that conditional formatting always treats the formulas as a array formula but it doesnt seem to do that when i have added it in via VBA.</o:p>
</NOW(),IF(E4:E6="""",FALSE,TRUE),FALSE))=TRUE,TRUE,FALSE)"<><NOW(),IF(E4:E6="""",FALSE,TRUE),FALSE))=TRUE,TRUE,FALSE)"< font>

<o:p>Any Idea's?</o:p>
<o:p></o:p>
<o:p>Thanks</o:p>
<o:p>tigs</o:p>
</NOW(),IF(E4:E6="""",FALSE,TRUE),FALSE))=TRUE,TRUE,FALSE)"<></NOW(),IF(E4:E6="""",FALSE,TRUE),FALSE))=TRUE,TRUE,FALSE)"<>
 
Upvote 0
First guess, run your VBA on a single cell, not a range. Does it work?
 
Upvote 0
Thank you Glenn

Is that what you meant?

Code:
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=IF(SUM(G1*H1,G2*H2,G3*H3)>3,TRUE,FALSE)"

I tried this vba code and it works fine.

Thankyou
tigs
 
Upvote 0
No, I actually meant:

Code:
Range("G11").FormatConditions.Add Type:=xlExpression, Formula1:="=IF(SUM(G1:G10*H1:H10)>3,TRUE,FALSE)"
 
Upvote 0
Glenn
sumproduct does work.

Although my actual formula that i need to work is a bit more than that. I was using that as an example as it shows the issue with the array formula.

Code:
=IF(OR(IF(F4:F10<NOW(),IF(F4:F10="",FALSE,TRUE),FALSE))=TRUE,TRUE,FALSE)

Its comparing dates in cell range and any are before Now conditional formatting is activated.

I have also just thought of a workaround by utilising another column which gets around the array formula issue with the conditional formatting
But would like to keep the worksheet tidy and not use an extra column

Any further help you can offer on this matter, would be greatly appreciated.

thanks
tigs
 
Upvote 0
Can you spaces either side of your " < " and " > " signs when you next post your formula ... I should be able see it then. I can't guess whether SUMPRODUCT is appropriate or not at the moment.
 
Upvote 0

Forum statistics

Threads
1,224,558
Messages
6,179,512
Members
452,920
Latest member
jaspers

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