manual and macro run differences

R

rumkus

Columns("A:A").Select
Selection.Replace What:="2009", Replacement:="09", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False

When I do it manually above replacement I received good results
(Text to date conversion)
But when record and run as macro I received comical result.
I really wonder why ? Any idea why this happens ? Thank you.
 
A

AltaEgo

Are you trying to change the format of something already recorded as a date?
If so, find and replace is not the way to achieve the desired result. You
need to format your date field according to you preferences.

In the worksheet, refer to the Text() function. In VBA see the Format()
function.
 
R

rumkus

Are you trying to change the format of something already recorded as a date?
If so, find and replace is not the way to achieve the desired result. You
need to format your date field according to you preferences.

In the worksheet, refer to the Text() function. In VBA see  the Format()
function.

--
Steve







- Show quoted text -


Hi Steve, thank you for your reply.
I copy a word table into excel as text but date field doesnt't work.
So when I manually change 2009 to 09 whole column becomes proper date.
I recorded the replacement into a macro and run but the result is
different than manual replacement.
If only i managed to run some word vba codes through excel like
replacement as i have to do some other replacements after copying the
table.
 
A

AltaEgo

To convert your text dates to proper dates, use the Datevalue() function

If you have a text date in A1:

=Datevalue(A1)

You will see a number in the cell in which you entered the above formula. to
change this to a date, Format the cell and choose your date formula.

To get this back into A1 in place of the original value, copy, paste
special, value.
 

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