+ Reply to Thread
Results 1 to 4 of 4

Unable to maintain formatting on find/replace

Hybrid View

samwise78 Unable to maintain formatting... 10-20-2012, 05:16 PM
mike7952 Re: Unable to maintain... 10-20-2012, 05:30 PM
samwise78 Re: Unable to maintain... 10-20-2012, 05:38 PM
mike7952 Re: Unable to maintain... 10-20-2012, 05:50 PM
  1. #1
    Registered User
    Join Date
    10-17-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    2

    Unable to maintain formatting on find/replace

    Hi there,

    New to the forum so be gentle!

    Working on a sheet to automatically replace specific text in a search string with either today's date or yesterday's date in UK format (dd/mm/yyyy)
    dd/mm/yyyy to be replaced with today's date
    xx/xx/xxxx to be replaced with yesterday's date

    My really basic code works to an extent but flips the formatting into US date format every time it is run..

    Attached what I'm working on - am a novice when it comes to this - think I'm missing something obvious..

    Any help would be gratefully appreciated

    thanks
    Sam
    Attached Files Attached Files

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Unable to maintain formatting on find/replace

    Try this use Format(Range,"dd/mm/yyyy")

    Replacement:=Format(Range("C3"), "dd/mm/yyyy")
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Registered User
    Join Date
    10-17-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Unable to maintain formatting on find/replace

    Absolutely spot on - works perfectly..
    Was staring me in the face the whole time!

    Thanks
    Sam

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Unable to maintain formatting on find/replace

    You can do away with Select and copy to.

        Range("C3").Select
    Selection.Copy
    and just use

    Cells.Replace What:="dd/mm/yyyy", Replacement:=Format(Range("C3"), "dd/mm/yyyy"), LookAt:= _
    xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
    ReplaceFormat:=False
    
    Cells.Replace What:="xx/xx/xxxx", Replacement:=Format(Range("C5"), "dd/mm/yyyy"), LookAt:= _
    xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
    ReplaceFormat:=False

+ 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