Go Back   TechArena Community > Software > Windows Software
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , ,

Sponsored Links



How to display decimal numbers in Excel sheet

Windows Software


Reply
 
Thread Tools Search this Thread
  #1  
Old 05-05-2009
Halina's Avatar
Member
 
Join Date: May 2008
Posts: 982
How to display decimal numbers in Excel sheet

I am in big trouble with my Excel sheet. How to choose a format to two decimal for a cell that does not display "point zero zero"? I mean I want my some cell in my Excel sheet should include 2 decimal values. But every time I get a whole number.
Reply With Quote
  #2  
Old 05-05-2009
Gunilla's Avatar
Member
 
Join Date: May 2008
Posts: 983
Re: How to display decimal numbers in Excel sheet

It is certainly easier, but if you do not know the answer here is a solution to adapt:

Code:
Private Sub Worksheet_Change (ByVal Target As Range) 
lim = Range("a65000" ).End(xlUp).Row
For i = 1 To lim 
Cells (i, 1). Select 
Selection.NumberFormat = "0.00" 
If Round (Selection) = Selection Then Selection.NumberFormat = "0" 
Next i 
End Sub
attention, the loop is done on all the cells each time you enter data in the table. If you want to do so only for the current cell, use target:

Code:
Private Sub Worksheet_Change (ByVal Target As Range) 
target.Select 
Selection.NumberFormat = "0.00" 
If Round (Selection) = Selection Then Selection.NumberFormat = "0" 

End Sub
Reply With Quote
  #3  
Old 05-05-2009
sergioKomic's Avatar
Member
 
Join Date: May 2008
Posts: 918
Re: How to display decimal numbers in Excel sheet

Gunilla solution gives the most correct (since no commas).

Nevertheless, it would be nice to apply this function only on cells that have a certain format (style number). Otherwise, if the Excel sheet contains style data, the function will return an error quickly.

Hence my question: how to test the formatting of a cell

If <format then cell = numerical>
... as per Gunilla code
else
exit
end
Reply With Quote
  #4  
Old 05-05-2009
Raine's Avatar
Member
 
Join Date: May 2008
Posts: 3,287
Re: How to display decimal numbers in Excel sheet

To encode this macro, in Excel (with your file open), type ALT + F11. A window will open Visual Basic. There in the window of exploration left, you have a tree. Double-click on "Sheet1", a blank window will open as a window.

Simply code as given by Gunilla. Attention, you must either stick the first solution or the second, but not both (or comment either by adding an apostrophe before each line).

Save and close. That is, the macro is applied to each cell that you change.
I tested it and it works very well, except just that the macro does not distinguish between a cell-type number or another. So if you come back for example "Y" in a cell, such as the macro will run on any cell in progress, the macro will return an error every time it returns a non-digital.

There are certainly features of types of conversions to make calculations, but I do not know them and they are certainly less "certain" that directly use the correct types.
Reply With Quote
Reply

  TechArena Community > Software > Windows Software


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to display decimal numbers in Excel sheet"
Thread Thread Starter Forum Replies Last Post
How to change negative numbers to positive numbers in Excel Shaina Na Microsoft Project 3 08-01-2012 05:35 PM
How to reject decimal numbers in Python? The Recruiter Software Development 5 15-01-2010 05:43 PM
Automatically display negative numbers in red in Excel 2007 SpearMan Tips & Tweaks 2 20-03-2009 12:10 AM
How to display only part of a decimal number Gauresh Software Development 2 31-01-2009 09:20 AM
Excel Issue for decimal Point Bassus Windows Software 3 15-01-2009 10:54 AM


All times are GMT +5.5. The time now is 05:21 PM.