Number formatting issue in Excel

asokaw

New Member
Joined
Jun 24, 2013
Messages
39
Office Version
  1. 2013
Hi

I need to format a number to show 2 decimals when it has decimal numbers, otherwise not

I used #.00 as the format but the problem is when there are no decimals even the .( decimal point ) is shown. how can I
not show that decimal point

eg. 78 is shown as 78. ( I dont need the decimal to be shown )

Thanks
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try the following code.

You need to select the cell(s) you want to format before running the macro.

Code:
Sub Test()
    
    Dim Cell As Range
    
    If TypeName(Selection) <> "Range" Then Exit Sub
    
    For Each Cell In Selection
        If IsNumeric(Cell.Value) Then
            If Int(Cell.Value) <> Cell.Value Then
                Selection.NumberFormat = "0.00"
            End If
        End If
    Next Cell

End Sub
 
Upvote 0
Can I do this without a Macro by using only Formatting cells
 
Upvote 0
What you are asking is to Format the cell under certain conditions, hence use a "Conditional Formatting" Rule.

Highlight the area that you want the rule to apply to,
On the Home tab, click: Conditional Formatting, Slide down to " New Rule ",
Click: " Use a formula to determine which cells to format ",
In the pop up box formula bar type: =$B2=INT($B2)
( In the formula use the cell reference of the top left cell of your highlighted range. )
Then click the " Format... " button, Choose the " Number " tab, Choose " Number " on the left side,
Set the decimal places to zero, and click the little box if you want a comma when having thousands listed,
Then click: " OK ", then click: "OK", then click: " APPLY ",
Then click: " New Rule ",
Click: " Use a formula to determine which cells to format ",
In the pop up box formula bar type: =$B2>INT($B2)
( In the formula use the cell reference of the top left cell of your highlighted range. )
Then click the " Format... " button, Choose the " Number " tab, Choose " Number " on the left side,
Set the decimal places to 2, and click the little box if you want a comma when having thousands listed,
Then click: " OK ", then click: "OK", then click: " APPLY ".

That should get you there...
Have a great week!!!
 
Upvote 0
My suggestion would be to have standard format with 2 decimals as originally posted and only the first rule for conditional formatting from the previous post.
If you have your numbers in a column and want to align the 2 different formats, then you should supply conditional format #_._0_0
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top