Need to convert a fraction to a decimal

ouadad

Board Regular
Joined
Jun 19, 2005
Messages
213
The output of a program provides a fraction like 6519/231 . I need to convert this to a decimal. I tried going from "general" to "number" in the drop down tab, but it does nothng. I really need to be able to put an equal sign in front of every entry, but I have hundreds. Any advice?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
How does the data get to excel? Is there any other data that you don't want to become a formula?
 
Upvote 0
You could have a macro to do it that you manually trigger, or you can have a macro to do it that's triggered by the Worksheet_Change event...

the basic premise is going to be:

Code:
Worksheets("Sheet1").Range("A1").Formula = "=" & Worksheets("Sheet1").Range("A1").Value

This is essentially adding an equals sign. If you want to do this for many cells, you can do something like so:

Code:
Sub ConvertToFormula()
Dim rngCell As Range
For Each rngCell In Worksheets("Sheet1").Range("A1:Z100")
    If rngCell.Value <> "" And Not rngCell.HasFormula Then
        rngCell.Formula = "=" & rngCell.Value
    End If
Next
End Sub

This will currently convert any cell within Range A1:Z100 that is not blank and does not have a formula.
 
Upvote 0
Alternatively, we can use evaluate:

Code:
Sub ConvertToFormulaTest()
Dim prevValue As Variant
Dim rngCell As Range
For Each rngCell In Worksheets("Sheet1").Range("A1:Z100")
    If rngCell.Value <> "" And Not rngCell.HasFormula Then
        prevValue = rngCell.Value
        rngCell.Value = Evaluate(rngCell.Value)
        If IsError(rngCell.Value) Then rngCell.Value = prevValue
    End If
Next
End Sub

So this will likely be the better way of handling this. Anything that produces an error from the evaluate line will get reset to the previous value...so if there are cells that contain text, they will remain unchanged. Anything that is evaluate-able, such as your fractions, will get changed to decimal form with the evaluate line. Hopefully that makes sense.

This is still only looking at A1:Z100 on Sheet1...you'll need to adjust those accordingly.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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