ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   conditional formatting (https://www.excelbanter.com/excel-discussion-misc-queries/162150-conditional-formatting.html)

Steve

conditional formatting
 
I want to select a column of numbers (B1:B1200) and format them with 4
decimals if they're between zero and one and with 2 decimals otherwise. I'd
like to do this without an add-in (vba is ok). Thanks.

Gary''s Student

conditional formatting
 
Just run:

Public Sub reform()
Set r = Range("B1:B1200")
For Each rr In r
v = rr.Value
If v 0 And v <= 1 Then
rr.NumberFormat = "0.0000"
Else
rr.NumberFormat = "0.00"
End If
Next
End Sub

and each item in the column will be correctly formatted.
--
Gary''s Student - gsnu200750


"Steve" wrote:

I want to select a column of numbers (B1:B1200) and format them with 4
decimals if they're between zero and one and with 2 decimals otherwise. I'd
like to do this without an add-in (vba is ok). Thanks.


JE McGimpsey

conditional formatting
 
One way:

Format/Cells/Number/Custom

[<0]-0.00;[<=1]0.0000;0.00


In article ,
Steve wrote:

I want to select a column of numbers (B1:B1200) and format them with 4
decimals if they're between zero and one and with 2 decimals otherwise. I'd
like to do this without an add-in (vba is ok). Thanks.


John Bundy

conditional formatting
 
For positive numbers:
=IF(B11,ROUND(B1,2),ROUND(B1,4))

--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"Steve" wrote:

I want to select a column of numbers (B1:B1200) and format them with 4
decimals if they're between zero and one and with 2 decimals otherwise. I'd
like to do this without an add-in (vba is ok). Thanks.



All times are GMT +1. The time now is 11:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com