Conditional Number Formatting a range based on a different cell value

Edgarvelez

Board Regular
Joined
Jun 6, 2019
Messages
197
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

Tried to record a conditional format but it's not working.
In cell C11 I have a drop down and when I select LB. I want to change the number format to #,##0.00 on range D21:E1048576

***************************************************
This the recorded code that does not work

Range("D21:E1048576").Select
Selection.NumberFormat = "#,##0.00"
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$C$11=""LB."""
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
ExecuteExcel4Macro "(2,1,""#,##0.00"")"
Selection.FormatConditions(1).StopIfTrue = False
***************************************************
I added a screen shot to simplify the goal I and trying to get.
 

Attachments

  • Number Formatting.JPG
    Number Formatting.JPG
    101.4 KB · Views: 6

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I don't know why recording a CF for Excel is so difficult. I would change the macro to this:

VBA Code:
Dim Rng As Range
  Dim Cnt As Long
  
  Set Rng = Range("D21:E1048576")
  Rng.FormatConditions.Delete
  Rng.FormatConditions.Add Type:=xlExpression, Formula1:="=$C$11=""LB."""
  Cnt = Rng.FormatConditions.Count
  Rng.FormatConditions(Cnt).SetFirstPriority
  Rng.FormatConditions(Cnt).NumberFormat = "#,##0.00"
  Rng.FormatConditions(Cnt).StopIfTrue = False
 
Upvote 0
Solution
I don't know why recording a CF for Excel is so difficult. I would change the macro to this:

VBA Code:
Dim Rng As Range
  Dim Cnt As Long
 
  Set Rng = Range("D21:E1048576")
  Rng.FormatConditions.Delete
  Rng.FormatConditions.Add Type:=xlExpression, Formula1:="=$C$11=""LB."""
  Cnt = Rng.FormatConditions.Count
  Rng.FormatConditions(Cnt).SetFirstPriority
  Rng.FormatConditions(Cnt).NumberFormat = "#,##0.00"
  Rng.FormatConditions(Cnt).StopIfTrue = False

I don't know why recording a CF for Excel is so difficult. I would change the macro to this:

VBA Code:
Dim Rng As Range
  Dim Cnt As Long
 
  Set Rng = Range("D21:E1048576")
  Rng.FormatConditions.Delete
  Rng.FormatConditions.Add Type:=xlExpression, Formula1:="=$C$11=""LB."""
  Cnt = Rng.FormatConditions.Count
  Rng.FormatConditions(Cnt).SetFirstPriority
  Rng.FormatConditions(Cnt).NumberFormat = "#,##0.00"
  Rng.FormatConditions(Cnt).StopIfTrue = Fa
[/QUOTE]
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

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