Conditional Formatting via VBA

gaj_cod

New Member
Joined
Jun 3, 2008
Messages
25
Hi folks

While doing Conditional Formatting via VBA, if we assign String array to Formula1 then CF is not taking place..

instead if we hardcode the same, its working..

Following is the code

Dim rangeArray() As Double
Dim TheRange As Range
Dim rangeFormulaArray() As String
Set TheRange = Range(Cells(vFRow + i * vRowPerModel + 1, vFCol + vFCStart), Cells(vFRow + i * vRowPerModel + 1, vFCol + vColCount - 1))
ReDim rangeFormulaArray(vFRow + i * vRowPerModel + 1 To vFRow + i * vRowPerModel + 1, vFCol + vFCStart To vFCol + vColCount - 1)

For j = vFCol + vFCStart To vFCol + vColCount - 1
rangeFormulaArray(vFRow + i * vRowPerModel + 1, j) = "=" & Cells(vFRow + i * vRowPerModel + 1, j).Address & "<> RoundDown(" + Cells(vFRow + i * vRowPerModel + 1, j).Address & " / " & vMCQ & ", 0) * " & vMCQ Next j
TheRange.FormatConditions.Delete
TheRange.FormatConditions.Add Type:=xlExpression, Operator:=xlNotEqual, Formula1:=rangeFormulaArray
TheRange.FormatConditions(1).Font.Bold = True

Next j




Please guide.

Any help will be cordially appreciated.

Regards
Gajendra
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I was not sure if array formulas even work in Conditional Formatting....are you saying when you "hard code" the formula that it is entered in the CF criteria - but I'm curious does it actually work ?

What does this formula look like when it is finished - the use of so many variables makes it a bit cryptic.

What's the purpose of the conditional formatting here...another way to do this would be to enter the formula into a regular (hidden) column, then use the CF formula to simply refer to the result in that cell. That way you aren't dealing with so much processing in the CF itself.

It's not completely relevant but in CF formulas I like to use OFFSET() so that the formula is not affected adversely by deleted rows or columns that could ruin the references in the CF.

Alex.
 
Upvote 0
Hi Alex

Thanks for your response. But we are looking for CF via arrays because we have got significant improvement in the performance through arrays so that is why trying to give it a shot.

I am waiting for other experts also to put their thoughts into the same.

This is urgent guys !!!


Regards
Gajendra
 
Upvote 0
I'd still recommend you post your formula the way it "really looks". Its just hard to see what that formula is...

Sometimes it works better to create the formula in a separate statement:

Code:
Dim strFormula as String
strFormula = "=RC*RC[1]"
Range("A2").FormulaR1C1 = strFormula
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,214
Members
448,874
Latest member
b1step2far

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