+ Reply to Thread
Results 1 to 10 of 10

Replace function not working in Macro

  1. #1
    Registered User
    Join Date
    02-25-2020
    Location
    Shiner, Texas
    MS-Off Ver
    Office 365 ProPlus
    Posts
    9

    Replace function not working in Macro

    Hello All, needing help with the replace function. If a cell has the following contents (906, 910, 911) my macro is not replacing the numbers with text. I have tried taking the commas out, and have same issue. After the macro is completed. I try to do the replace function manually and it will not find the data. I then tried to just see if excel would find the data, and it found it. Then did the replace function again and it will now replace it after finding it.. I have duplicated this result several times. It will not replace until I run the find manually. Makes no sense to me.

    I am trying to get it to change each number in the cell to different text. I.E. (906, 910, 911) would translate to (Hello, Help, Please)

    Code in macro:

    Columns("L:L").Select
    Selection.Replace What:="906", Replacement:="Hello", LookAt:= _
    xlWhole, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
    ReplaceFormat:=False
    Selection.Replace What:="910", Replacement:="Help", LookAt:=xlWhole _
    , SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
    ReplaceFormat:=False
    Selection.Replace What:="911", Replacement:="Please", LookAt:= _
    xlWhole, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
    ReplaceFormat:=False

    Thanks in advance.

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: Replace function not working in Macro

    "906" is text, not a number. If you leave the double quotes out, it is a number.

  3. #3
    Registered User
    Join Date
    02-25-2020
    Location
    Shiner, Texas
    MS-Off Ver
    Office 365 ProPlus
    Posts
    9

    Re: Replace function not working in Macro

    I took the "" out, and it still does not work on cells with multiple numbers/text... It works just fine on cells that only have one value in them.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: Replace function not working in Macro

    Re: does not work on cells with multiple numbers/text
    Can you give us some examples to work with?

    Please Login or Register  to view this content.
    Also, read the forum rules again about using code tags before you continue.

  5. #5
    Registered User
    Join Date
    02-25-2020
    Location
    Shiner, Texas
    MS-Off Ver
    Office 365 ProPlus
    Posts
    9

    Re: Replace function not working in Macro

    I have a sample included. The yellow highlighted cells are whats wrong. Those are codes for reasons why a ticket was closed out.
    The green highlighted cells were also code numbers that I had the macro change to words for reporting purposes.
    The macro works just fine for any cell that does not have more than one code number in it.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    02-25-2020
    Location
    Shiner, Texas
    MS-Off Ver
    Office 365 ProPlus
    Posts
    9

    Re: Replace function not working in Macro

    Macro code is now attached too.
    Attached Files Attached Files

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Replace function not working in Macro

    It should be xlPart not xlWhole, and the column is K not L.
    If posting code please use code tags, see here.

  8. #8
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,522

    Re: Replace function not working in Macro

    Does this work on your original?
    On your attachment, it is Column K your working with, not Column L.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-25-2020
    Location
    Shiner, Texas
    MS-Off Ver
    Office 365 ProPlus
    Posts
    9

    Re: Replace function not working in Macro

    Thank you, I will try the xlpart. The macro does more stuff before changing the codes, so the column was originally L, but another column gets deleted so it becomes column K

  10. #10
    Registered User
    Join Date
    02-25-2020
    Location
    Shiner, Texas
    MS-Off Ver
    Office 365 ProPlus
    Posts
    9

    Re: Replace function not working in Macro

    The xlPart fixed the issue. Thank you all! Much appreciated!!

+ 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. Replies: 3
    Last Post: 11-19-2019, 11:55 AM
  2. Find & Replace function not fully working
    By Blesbie in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-14-2017, 09:19 AM
  3. REPLACE function not working on a Mac??
    By JBeaucaire in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-07-2016, 06:07 AM
  4. [SOLVED] VBA Replace Function Not Working
    By nevi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-12-2014, 05:06 PM
  5. [SOLVED] Find/Replace function not working - please help :)
    By gregrach in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-15-2014, 11:16 AM
  6. find and replace function is not working correctly
    By rhino87 in forum Excel General
    Replies: 2
    Last Post: 10-10-2012, 04:16 PM
  7. Replace Function isn't working
    By Adam in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-06-2005, 05:00 PM

Tags for this Thread

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