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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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
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,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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