问题
I have a set of data extracted from Hyperion Essbase in which I would like to add a rule over those cells. I've tried conditional formatting, but I'm not getting what I want.
For example some cells contain 0.000
or 13.5232
and the rule I want over them is IF(ROUND(ABS(Cell Value),2)<=0.01,0,Cell Value)
I'm not sure if my formula is the one that doesn't make sense or I'm not using conditional formatting correctly. I don't need any cells highlighted, I would just like the data in the cells rounded if they fit the criteria in my formula.
回答1:
From your question, it seems like you want to use conditional formatting to change how the numbers are formatted (for numbers whose absolute value, rounded to 2 decimal places, is <= 0.01, they should be formatted with 0 decimal places, i.e., show as 0).
This can absolutely be achieved with conditional formatting (no VBA required).
- Select the cells you wish to apply the conditional formatting to.
- Open the Conditional Formatting Rules Manager, and create a .
- Select Use a formula to determine which cells to format, enter the formula that identifies the cells you wish to format (make sure you eschew absolute references).
- Click the Format button and select Number > 0 Decimal places ()
- Click OK 3 times to return back to the spreadsheet, and you should see the values formatted as desired:
回答2:
If you just want to change the displayed number format then this should do.
Sub cfrZeroes()
With Worksheets("sheet2").UsedRange.Cells
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, _
Formula1:="=ROUND(ABS(" & .Cells(1).Address(0, 0) & "),2)<=0.01"
.FormatConditions(.FormatConditions.Count).NumberFormat = "\0"
End With
End Sub
That will change -0.015 to 0.015 to look like 0 but it won't change the underlying raw value.
来源:https://stackoverflow.com/questions/51065070/how-do-you-add-a-rule-to-cells-in-excel