conditional formatting

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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.
 
Back
Top