How do I make excel show fractions as decimals? Formatting column as Number does not work.

ManDrone

New Member
Joined
Jan 3, 2011
Messages
12
I have a macro for importing data from an XML file and converting it to CSV (after some manipulation, amputation etc.). One field represents the odds of something happening. This means the field contains mostly integers and some fractions. I want all fractions to display (and save in .csv) as decimals w/2 sig figs. In other words, if the field right now displays as 3/5 I want it to convert to 0.60.

I have indicated that the column should be Numeric. I thought this would make 3/5 turn into 0.60 but it does not, as nothing changes. I figured out that it only changes if I DOUBLE CLICK on the fractional value (??!?) after setting the column as a Number. Note that I change nothing in the cell, just double click and then move away.

How do I, within a macro, tell excel I want junk like 1/5 to render as 0.20?
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
ManDrone,

What version of Excel are you using?

Please attach screenshots of your workbook or a sample workbook that accurately portrays your current workbook on one sheet, and what it should look like 'After' on another sheet. This makes it much easier to see exactly what you want to do, as well as shows us whether there is a consistent number of rows between tables and such.

Here are three possible ways to post small (copyable) screen shots directly in your post:

Please post a screenshot of your sheet(s), what you have and what you expect to achieve, with Excel Jeanie HTML 4 (contains graphic instructions).
http://www.excel-jeanie-html.de/html/hlp_schnell_en.php

or
RichardSchollar’s beta HTML Maker -...his signature block at the bottom of his post

or
Borders-Copy-Paste
 
Upvote 0
Try this after formatting the cells as number with 2 decimals and selecting the cells:

Code:
Sub Test()
    Dim Cell As Range
    For Each Cell In Selection
        Cell.Value = Cell.Value
    Next Cell
End Sub
 
Upvote 0
The macro you provided works. Thank you. One nitpick is it's awfully slow - I wish I knew a way to affect all values in the column in one fell swoop. Or that Excel listened to me when I said "hey jerk - when I say "number" change to number".

Using Excel 2007 FYI.

Thanks for the help.
 
Upvote 0
if you have written a macro to do all your stuff, then find the line which places the data back to the cell and add a format:

eg
Code:
    Cells(myrow,mycol).value=Format(Myfraction,"0.00")

if this doesnt work try
Code:
    Cells(myrow,mycol).value=str(Format(Myfraction,"0.00"))

also check the column format in the sheet and make sure it is not forcing the format, but i am pretty sure that vba format will override sheets formating
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,626
Members
449,093
Latest member
catterz66

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