+ Reply to Thread
Results 1 to 6 of 6

using excel to replace a particular character, if it is present

  1. #1
    Registered User
    Join Date
    06-03-2011
    Location
    Hatfield, England
    MS-Off Ver
    Excel 2007
    Posts
    19

    Question using excel to replace a particular character, if it is present

    Hello all,

    1st time post, so apologies if it is in the wrong section etc.

    I am attempting to write a formula to change a character in text, but only if it is present.

    So, for example, the text is "AB1oABCD" it should be AB10ABCD [The o replaces with a zero]

    The logic is something along the lines of 'If the 4th character is the letter o, replace it with the number 0, if it is not, then leave the text as it is'

    i have tried using the LEFT and RIGHT functions to point an IF function at the 4th character, then if the IF says there is a o in the 4th character position, REPLACE is used to change it to a 0. I can't seem to get it to work. I would like to avoid VBA and macros if possible.

    Can anyone help ?

    Thanks in advance !

    EDIT: Solved, well i think so, see my post further down.
    Last edited by adx1000; 06-07-2011 at 07:29 AM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: using excel to replace a particular character, if it is present

    Hi adx1000 and welcome to the forum,
    Try
    Please Login or Register  to view this content.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    05-11-2011
    Location
    Miami, FL
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: using excel to replace a particular character, if it is present

    Assuming that your data starts in colum A1, and you want to avoid macros what I would do is

    in column B....=left(A1,3)...then copy and paste special "values"
    in column C....=mid(A1,4,1)..then copy and paste special "values." At this point I would highlight column C and find and replace "o" with "0."
    in column D...=mid(A1,5,10) I don't know how long the average values are but from your example it seems that this should work. Again, copy and paste special "values."

    Finally, in column E =concantenate(B1,C1,D1)


    Hope this works!

  4. #4
    Forum Contributor
    Join Date
    05-27-2008
    Location
    Newcastle Upon Tyne UK
    MS-Off Ver
    XP Excel 2003
    Posts
    105

    Re: using excel to replace a particular character, if it is present

    already solved.

    edvwvw

  5. #5
    Registered User
    Join Date
    06-03-2011
    Location
    Hatfield, England
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: using excel to replace a particular character, if it is present

    Quote Originally Posted by MarvinP View Post
    Hi adx1000 and welcome to the forum,
    Try
    Please Login or Register  to view this content.
    Thanks for your reply. Would that not replace all "o" with 0 ?
    I only want to change the 4th character, so if a "o" was present elsewhere, it would remain unchanged.

    e.g. Ao1o1BCD ---> Ao101BCD or XoXoXXXX ----> XoX0XXXX

    Thanks again !

  6. #6
    Registered User
    Join Date
    06-03-2011
    Location
    Hatfield, England
    MS-Off Ver
    Excel 2007
    Posts
    19

    Smile Re: using excel to replace a particular character, if it is present

    Quote Originally Posted by miamihurricanes View Post
    Assuming that your data starts in colum A1, and you want to avoid macros what I would do is

    in column B....=left(A1,3)...then copy and paste special "values"
    in column C....=mid(A1,4,1)..then copy and paste special "values." At this point I would highlight column C and find and replace "o" with "0."
    in column D...=mid(A1,5,10) I don't know how long the average values are but from your example it seems that this should work. Again, copy and paste special "values."

    Finally, in column E =concantenate(B1,C1,D1)


    Hope this works!
    Thanks for the reply, I can see that this would work, essentially splitting out the 4th character, changing it, then concantenate it all back together.

    I just figured that there is a way of pointing excel functions at a partcular character in a cell, then instructing it to change that character from "o" to "0".

    EDIT: Just tried this, and it does indeed work. However it seems a little long winded for a replace. I will have an experiment with the MID function however. Thanks.
    If anyone has any other ideas, then im all ears !

    EDIT 2: I think i may have cracked it, using the MID function.

    along the lines of =IF((MID(A1,4,1))="o",REPLACE(A1,4,1,0),A1)

    Thanks for the help everyone. If there is a more graceful way, let me know !
    Last edited by adx1000; 06-03-2011 at 10:10 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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