+ Reply to Thread
Results 1 to 11 of 11

Find and replace recorded macro messes up the dates

  1. #1
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Find and replace recorded macro messes up the dates

    What I need to achieve is to convert the info in column U which contains dates that are saved as text in format xx.xx.xxxx to change them into dates format dd/mm/yyyy (recognised as dates, not as text). You can do find "." and then replace "/" which does the trick. But as soon as I do the same thing with recorded macro it messes up some of the dates as they are still kept as text. It changes the "." with "/" on all cells but some of them are picked up by excel as dates others remain as text. You can really easily tell which one it recognizes as text and which as dates as text is kept aligned left, dates are aligned to right. To make things even more awkward the ones it picks up as date it swaps the dd and mm. If before its 09.03.2011 then after its 03.09.2011. Even when you change the format to dd/mm/yyyy the date remains the same 09.03.2011. If you do the process manually then problems excest. Please help with better solution.

    Here is my rubbish recorded macro.
    Please Login or Register  to view this content.
    I will attach the xls as well.



    Some other solution than then recorded macro I have is needed.
    Please help
    Attached Files Attached Files
    Last edited by rain4u; 02-19-2011 at 09:22 AM. Reason: Mistake with SOLVED perfix

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Find and replace recorded macro messes up the dates

    Do you really need a macro for this?

    In a spare column in row 2
    Please Login or Register  to view this content.
    Drag/Fill Down

    Copy this column and PasteSpecial > Values to U2
    Format Column U as date.

    Do the same for any other date column you need to change.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Find and replace recorded macro messes up the dates

    Unfortunately I do need macro for this. I work with lots of reports generated by software called SAP. I need to deal with this report every single day at work so running macros is a good solution to reduce your workload and have bit more time to deal with other important tasks. I already have loads of macros that are doing other tasks and they are depending on this macro. I only now figured out it has a problem. So this particular type of report has this silly date formating. If I would feel happy with manually sorting out the dates in that column U, I would then do highlight the column do find and replace and problem would be sorted. As I said it works when you do it manually. Which is even easier option than suggested. Its when you run the recorded macro it messes up. Don't know why that is happening. Its very silly. Try it. Do it manually, highlight the column u, Ctrl+F find . replace with /, press ok, see the result, undo it and then run the recorded macro.You can see then the difference between doing it manually or running this macro. Its then all messed up. PS! For check purpose col T and col U should have the same dates.


    Any ideas that would work as a macro.

    Cheers
    Rain
    Last edited by rain4u; 02-19-2011 at 04:36 AM.

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Find and replace recorded macro messes up the dates

    Try this

    Select any cell in the column you need to convert the strings to dates and run this macro
    Please Login or Register  to view this content.

    This assumes that all the data in the column is a string formatted as your sample workbook or is blank, and the data begins in row 2

    N.B.
    Column IV is the last column in Excel 2003 and is used as a helper column in this macro.

    Hope this helps
    Last edited by Marcol; 02-19-2011 at 06:10 AM.

  5. #5
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Find and replace recorded macro messes up the dates

    hi, rain4u, try this:
    Please Login or Register  to view this content.
    Last edited by watersev; 02-19-2011 at 07:18 AM.

  6. #6
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Find and replace recorded macro messes up the dates

    Quote Originally Posted by watersev View Post
    hi, rain4u, try this:
    debug error with this line
    If a(i, 1) <> "" Then a(i, 1) = DateValue(a(i, 1))
    It has that a(i, 1) = DateValue(a(i, 1)) section highlighted in yellow


    Will try Marcol's code in a a minute

  7. #7
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Find and replace recorded macro messes up the dates

    Marcol's code working fine. Adjusted it to my liking. Thank to both of you for helping me out.

    I'm very happy that now I can move on again and develop my macros even further. Was kind of stopping point for me as testing some other macros.



    Thank you


    Rain

  8. #8
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Find and replace recorded macro messes up the dates

    actually here is your sample file and my code inside, everything works as it should on my side.
    Columns I, T, U are converted to normal dates: dd.mm.yyyy
    Attached Files Attached Files

  9. #9
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Find and replace recorded macro messes up the dates

    @watersev

    As rain4u is, to quote
    ...(to).. work with lots of reports generated by software called SAP
    I felt it would be more useful to select a column at a time as there is no saying how many columns might be involved. Maybe not.

  10. #10
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Find and replace recorded macro messes up the dates

    Quote Originally Posted by watersev View Post
    actually here is your sample file and my code inside, everything works as it should on my side.
    Columns I, T, U are converted to normal dates: dd.mm.yyyy
    tried it with your xls. Still same problem. I attached screen shot.
    Attached Images Attached Images

  11. #11
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Find and replace recorded macro messes up the dates

    hi, rain4u, the only suggestion on my part is that the function Datevalue under the VB help file comes from VB for applications. In order to use it appropriate reference should be turned on in VB - Tools - References - Visual Basic for Applications otherwise VB do not understand it. I'm glad you have working solution for you task though it was not mine, brgds

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1