I paste stock market data into Excel each night, and I always have to
manually fix certain entries, such as 1/2, which Excel always interprets
incorrectly as a date.
Thanks.
Patrick
Microsoft Excel MVP
________________
Robert Pearson <rober...@yahoo.com> wrote in message
news:ORlmmlYY$GA....@cppssbbsa02.microsoft.com...
Another approach is to let Excel paste in fractions as dates but then use a
macro to repair the damage. This macro scans a selection and where it sees
a date tries to convert it to a decimal.
Sub DatesToDec()
Dim Cell As Range
Application.ScreenUpdating = False
For Each Cell In Selection
If IsDate(Cell.Value) Then
Cell.NumberFormat = "0.00"
Cell.Value = Month(Cell.Value) / Day(Cell.Value)
End If
Next
End Sub
--
Jim Rech
Excel MVP
HTH!
AMS
=========
The problem is, I don't enter the prices. They are returned from the
Merrill Lynch site by the Web Query. I have no control over the format
of the incoming data, as that is determined by the web site being
queried. Reformatting the data after it is in the spreadsheet has no
beneficial effect, as it is simply overwritten when I next Refresh
Data. Also, reformatting as a fraction merely returns the numeric
equivalent of the date, not of the original fraction.
=========
You can simulate by pasting this in and using Data --> Text to Columns
"BAA",1/8,"1/21/2000"
"BAB",1/4,"1/21/2000"
"BAC",3/8,"1/21/2000"
"BAD",3/32,"1/21/2000"
"BAE",7/256,"1/21/2000"
Using Jim Rech's macro in this thread looks like the best solution,
until noting that 3/32 will be treated as a date and convert to 3.0
with Jim's macro since the month is 3 and the day is 1 so
3/1 will be the result.
Could certainly use a number or fraction option in the text to columns,
and in the format.
HTH,
David McRitchie, Microsoft MVP - Excel
My Excel Pages: http://members.aol.com/dmcritchie/excel/excel.htm
Dana DeLouis <da...@email.msn.com> wrote in message news:uG59quUZ$GA.258@cppssbbsa04...
> Is there a way to paste the fraction 1/2 into a cell and have Excel
> treat it
> like the value one-half (which it is) instead of the date Jan-2, (which
> it
> is not)?
>
> Thanks.
>
>
Yes, easy: type 0 1/2 (compare 1 1/2 for 1.5)
David Colver
Operis Analysis Kit, used by professional financial modellers,
www.operis.com/oak.htm
Perhaps a different approach would be to import it as text so Excel can not
do any unforeseen changes to the data. Then you can run your own macro. For
Excel 2000, maybe something along this line of code...
Sub TextToFraction()
Dim rng As Range
Dim V As Variant
For Each rng In Selection
V = Split(rng, "/")
rng = V(0) / V(1)
Next
Selection.NumberFormat = "###/###"
End Sub
Anyway, interesting problem. Dana
"David McRitchie" <DMcRi...@msn.com> wrote in message
news:uyf6NfVZ$GA.265@cpmsnbbsa04...
> > > Is there a way to paste the fraction 1/2 into a cell and have Excel
treat
> > it
> > > like the value one-half (which it is) instead of the date Jan-2,
(which it
> > > is not)?
> > >
--
Regards,
Tushar Mehta
www.tushar-mehta.com
--
In <uUkdVibZ$GA....@cppssbbsa02.microsoft.com>, Dana DeLouis
<da...@email.msn.com> wrote
I think the following macro will help to convert stock prices
that were **pasted** from HTML into Excel, but that appear as
dates back to fractions. Color added to show a date
converted back to a fraction. The coding could probably be
cleaned up a bit. Should handle text, general, *dates*
You will have to subject it to your own data and testing.
The purpose here is to fixup data after the pasting since there
doesn't really seem to be much that can be done beforehand,
except for turning on transition formulas during cutting/pasting.
Perhaps test for current year should include test for previous
year with an OR.
Sub TextToFraction()
'David McRitchie 2000-01-24 Stock Prices back to fractions
'Excel treats 1/2 as a date instead of a fraction
'http://www.deja.com/=dnc/getdoc.xp?AN=574126457
Dim rng As Range 'r-n-g as in range
For Each rng In Selection
If rng.NumberFormat = "@" Then
If InStr(1, rng.Value, "/") Then
rng.NumberFormat = "# ###/###"
Else
rng.NumberFormat = "General"
End If
If Trim(rng.Formula) <> "" Then rng.Value = Trim(rng.Value)
Else
If IsDate(rng) Then
rng.NumberFormat = "[Color 30]# ###/###"
If Year(rng) = Year(Now()) Then 'i.e. 7/8
rng.Formula = "=" & Month(rng) & "/" & Day(rng)
ElseIf Year(rng) < 1900 Then 'i.e. 7/267 entered into General
rng.Value = "=" & Month(rng) & "/" & Year(rng)
Else 'i.e. 29/32 or 61/64
rng.Value = "=" & Month(rng) & "/" & (Year(rng) Mod 100)
End If
End If
End If
Next rng
End Sub
Some of simulated stock prices data tested, after text to data
"BAA",1/8,"1/21/2000"
"BAB",1/4,"1/21/2000"
"BAC",3/8,"1/21/2000"
"BAD",3/32,"1/21/2000"
"BAE",7/256,"1/21/2000"
Any ideas on why 7/267 entered into General is treated as a
date in this macro when dates in Excel aren't recognized before 1900?
The date formats that have to be converted back to fractions
are d-mmm and mmm-yy in my testing, and perhaps should be
used instead of IsDate().
HTH, This or a better one will appear on my stock page later on.
David McRitchie, Microsoft MVP - Excel
My Excel Pages: http://members.aol.com/dmcritchie/excel/excel.htm
rather than reposting the thread look at them in Deja News
Question posed by Robert Pearson 18 Jan 2000
http://www.deja.com/=dnc/getdoc.xp?AN=574126457 (see thread)
Also in thread as on track Patrick Molloy, Jim Rech, Dana DeLouis, Tushar Mehta
Cecil Bankston posed similar question 11Jan 2000
http://www.deja.com/=dnc/getdoc.xp?AN=571052937
there was a suggestion to turn on transition formulas for the
duration of the cutting and pasting.