Vba to add a conditional format for currency?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I've tried everything I can think of but cant get this to work, please help
Below is the code I need to add a conditionl formating rule into excel.
The problem is I cant get it to add in the forming condition I want.
basicly I want it for format currency to $

please help if you can

heres my code:


VBA Code:
Sub A_AAAA()
    Range( _
        "F6:I26,G27,I27,F29:I48,G49:G50,I49:I50,F53:I61,G62,G64,I62,M6:M26,M29:M48,W29:Z49,W6:Z26" _
        ).Select

    Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=IF(AND($A$2=""Converted"",$A$3=""USD""),TRUE)"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    Selection.FormatConditions(1).StopIfTrue = False

    
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
It looks like you deleted out the line that tells the format.
It should look something like this:
Rich (BB code):
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    ExecuteExcel4Macro "(2,1,""$#,##0.00"")"
    Selection.FormatConditions(1).StopIfTrue = False
If you turn on your Macro Recorder and record yourself applying the Conditional Formatting rule to one of the cells, you should record the line of code that you need.
Then you can just copy and paste that into your code.
 
Upvote 0
This not an error, but your formula does not have to explicitly return the value TRUE. It just needs to be a boolean expression that will return TRUE or FALSE. This formula is the equivalent of yours:
Excel Formula:
=AND($A$2="Converted",$A$3="USD")
or in the code
VBA Code:
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=AND($A$2=""Converted"",$A$3=""USD"")"
It is not necessarily "better" but it's simpler.
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,472
Members
449,087
Latest member
RExcelSearch

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