I NEED NUMBER CUSTOM FORMAT FOR DECIMAL PLACES


Posted by YANECKC on December 27, 2001 9:37 AM

IF THERE IS WHOLE NUMBER WITH NO DECIMAL THE NUMBER
SHOULD APPEAR WITH NO DECIMAL POINT AND COMMAS AS BELOW
125
567
12,345
74,000

IF A NUMNER HAS A DECIMAL THEN NUMBERS SHOULD HAVE
PERIOD AS DECIMAL WITH 5 PLACES AND COMMAS.
SEE BELOW TO SEE EXAMPLES THE WAY THEY SHOULD APPEAR.

ALSO NEGATIVE NUMBERS SHOULD HAVE PARENTHESIS AND IN RED.

THANKS YANECK

125.13400
56.56000
879.80000
.67000
1.23450
.80000
23,980.70000

Posted by Dan on December 27, 2001 11:12 AM

I'm fairly certain that there is no way to do what you want to do using the regular "Format Cells" function. Using that function, you may specify different formats for positive, negative, zero values, and text values, but you can't differentiate between whole numbers and decimals there. You will probably need to write a VBA macro that checks the value of the cell and formats according to whether it is a whole number or a decimal.

The closest that I came to what you want, using the Format Cells function is:
#,##0.00000);[Red](#,##0.00000)

But again, that doesn't do what you want for the whole numbers. Let me know if you need more help.

Posted by Juan Pablo G. on December 27, 2001 12:20 PM

How about a simple UDF ?

Function MyFormat(Rng as Range) as String
If Not IsNumeric(Tmp) Then Exit Function
If Rng - Int(Rng) > 0 then
MyFormat = Format(Rng,"#,##0.00000")
else
MyFormat = Format(Rng,"#,##0")
End If
End Function

This is A STRING, but could be done with a SUB to keep values as numbers.

Juan Pablo G.

Posted by Juan Pablo G. on December 27, 2001 12:23 PM

Something like this:

Sub MyFormat2()
Dim Cll As Range
For Each Cll In Selection.SpecialCells(xlCellTypeConstants, xlNumbers).Cells
If Cll - Int(Cll) > 0 Then
Cll.NumberFormat = "#,##0.00000"
Else
Cll.NumberFormat = "#,##0"
End If
Next Cll
End Sub

This assumes that the user selects the interest range PRIOR running the macro.

Juan Pablo G.

Posted by Joe Was on December 27, 2001 12:50 PM

Current selection code

Sub numMat()
Selection.NumberFormat = "General"
If Selection - Int(Selection) = 0 Then
ActiveCell.NumberFormat = "#,###"
End If
If Selection - Int(Selection) > 0 Then
ActiveCell.NumberFormat = "#,##0.00000"
End If
End Sub

This will test the current selection for a remainder and then format the results accordingly. JSW



Posted by YANECKC on December 27, 2001 1:19 PM


JUAN

THE SUBFORMAT2 WORKS GREAT!

THAT'S EXACTLY WHAT I WAS LOOKING FOR.

THANK YOU AND HAPPY YEAR!

KEEP UP THE GREAT JOB!

YANECKC