Excel fraction not a date

F

FGM

Windows 2000, Excel 2003
How do you get excel to use a fraction as a fraction and not a date? I am
using a function that returns a fraction as a string. I then copy it and
paste it in a new cell as value.. I have tried formating the cell as a
decimal, as a fraction, it just keeps it as text or views it as a date....
any help would be appreciated.
Thanks.
 
G

Gary''s Student

It does not matter if its VBA or on the worksheet:

Sub frac()
Selection.Formula = "= 1/4"
Selection.Value = Selection.Value
End Sub


The space makes it a fraction and not a date. Format the cell to carrry the
proper number of digits in the numerator and denominator.
 
T

Tom Ogilvy

I think you would need to evaluate the fraction as a decimal and place that
in a cell. then format the cell as fraction.

It is unclear whether you are doing the copying with code or manually. If
manual, I can select the fraction in the formula bar and do ctrl+V, go to the
new cell and select it. Go to the formula bar and enter = then ctrl+C
and hit enter. Format the cell as fraction.
 
T

Tom Ogilvy

The equal sign makes it a fraction. The below works fine for me.

Sub frac()
Selection.Formula = "=1/4"
Selection.Value = Selection.Value
End Sub

as does manual entry
=1/4

This could be affected by the settings in the transition tab of
tools=>options.
 
S

ShaneDevenshire

Hi,

Here's one way - select the range and choose the command Format, Cells,
Number tab, Fraction and pick a format of your choice.

Then enter the number as fractions.
 
G

Gary''s Student

Thank you
--
Gary''s Student - gsnu200724


Tom Ogilvy said:
The equal sign makes it a fraction. The below works fine for me.

Sub frac()
Selection.Formula = "=1/4"
Selection.Value = Selection.Value
End Sub

as does manual entry
=1/4

This could be affected by the settings in the transition tab of
tools=>options.
 
F

FGM

I did say that it was a function.
dec2frac = LTrim(Str(intNumerator)) & "/" & LTrim(Str(intDenominator)) '
Display the numerator and denominator
This came from Erik Oosterwal..... He said to copy and paste it as a value
but that does not work on mine. Adding = "= " & the above puts an = sign as
text even when I format the field. My long way of finally doing it and it is
not a good answer was in the cell below formatted as a fraction.
=VALUE(LEFT(B6,FIND("/",B6,1)-1))/VALUE(MID(B6,FIND("/",B6,1)+1,10))

Thank you and I can try a sub that calls the function and puts in the
Selection.Formula = "= X"
Selection.Value = Selection.Value

Thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top