I'm sorry if this is basic, but I can't get the right code here (and I have reasoned thru much more complicated things than this, but alas ...)
I am trying to set a column of numbers to 2 decimal places, unless it is a zero, where I just want a "0" with no decimal places. I can do it with a formula to = "0", but it takes it as a text string, and when I sort the column from largest to small, it puts that "0" at the top.
Trying with a VBA loop.
What am I doing wrong? It keeps flagging the NumberFormat line, no matter what I try.
Cheers,
Rodger
I am trying to set a column of numbers to 2 decimal places, unless it is a zero, where I just want a "0" with no decimal places. I can do it with a formula to = "0", but it takes it as a text string, and when I sort the column from largest to small, it puts that "0" at the top.
Trying with a VBA loop.
What am I doing wrong? It keeps flagging the NumberFormat line, no matter what I try.
Cheers,
Rodger
Code:
Dim rng As Range
Dim rcell As Range
Set rng = Range("M8:M108")
For Each rcell In rng
If rcell = 0 Then
With rcell
.NumberFormat = "0"
End With
End If
Next rcell