+ Reply to Thread
Results 1 to 6 of 6

Replace works not in recorded VBA

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    826

    Replace works not in recorded VBA

    Hi all,
    I recorde a macro to replace my commas in amount with dots.
    Columns("AB:AB").Select
        Selection.Replace What:=",", Replacement:=".", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
    Works manually while recording it ok.
    But when I run the recorded macro it will not replace anything....

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Replace works not in recorded VBA

    Your code works for me, here is is cleaned up a bit.
        Columns("AB:AB").SpecialCells(xlCellTypeConstants, 23).Replace _
                What:=",", Replacement:=".", _
                SearchOrder:=xlByColumns, MatchCase:=True
    If you are trying to change the commas in an actual number, you would have to format the cells as text first.

  3. #3
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    826

    Re: Replace works not in recorded VBA

    Thanks but it does nothing for me.....
    Also when I first change the format...it still keeps showing "," and not "."

  4. #4
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    826

    Re: Replace works not in recorded VBA

    Let me sent a sample which does not work for me.
    My Office settings are Dutch so decimals separator is ",".
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    05-13-2014
    Location
    Best
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Replace works not in recorded VBA

    Hi

    Run it in Xcel2007. It works fine here.

    bart

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,454

    Re: Replace works not in recorded VBA

    The data in column A in your sample is numeric. With my regional settings, the decimal part is separated by a full stop (dot). In yours, it may be a comma (,).

    If I do a global replace (using your code) and change full stop to comma, it works but the data becomes text where there is a decimal part. I can then reverse the process and it becomes numeric again.

    Nothing wrong with the code as it stands.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Recorded macro doing more than recorded?
    By Trending in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-26-2014, 11:42 AM
  2. Replace Macro recorded code with more effective code
    By scaffdog845 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-12-2014, 01:09 AM
  3. [SOLVED] FormulaArray 255 charter limitation .Replace workaround no-longer works/unstable
    By stewegg in forum Excel Programming / VBA / Macros
    Replies: 31
    Last Post: 01-07-2014, 07:55 PM
  4. [SOLVED] Recorded Pivot Table Macro Doesn't Do What I Recorded!
    By diakonos1984 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-26-2013, 11:01 AM
  5. Find and replace recorded macro messes up the dates
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-20-2011, 06:22 AM

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