+ Reply to Thread
Results 1 to 11 of 11

Replace only one character in string.

  1. #1
    Registered User
    Join Date
    10-21-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    59

    Replace only one character in string.

    Dear Experts,

    Can some one give me vba code to replace only one character from string.

    For example:

    My - Name - is - Ali

    *remove the first "-" only and replace it by "/"

    so the result will be, My / Name - is - Ali.

    Thanks

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Replace only one character in string.

    This seems to work...
    Please Login or Register  to view this content.
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Replace only one character in string.

    Hi,

    Please Login or Register  to view this content.
    Rgds
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

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

    Re: Replace only one character in string.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-21-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Replace only one character in string.

    Quote Originally Posted by Ron Coderre View Post
    This seems to work...
    Please Login or Register  to view this content.
    Thanks everybody specially Ron, these all options worked perfectly

  6. #6
    Registered User
    Join Date
    12-29-2011
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Replace only one character in string.

    Can I please have a code to do the same thing except to a whole column or range?

  7. #7
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Replace only one character in string.

    something like this
    Please Login or Register  to view this content.
    for each cell in selection
    Best Regards
    MaczaQ
    ---------------------------------------------------------------------------------------------------------------------------
    If you are satisfied with the solution(s) provided, please mark your thread as Solved
    If you are pleased with my answer consider to rate it. To thank someone who has helped you, click on the star icon below their name.
    - This way you will add him some reputation points ... thanks in advance.

  8. #8
    Registered User
    Join Date
    12-06-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    20

    Re: Replace only one character in string.

    Name the range you want to carry out the macro (i've named it "range1") and it should find and replace all cells within the defined range


    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    12-29-2011
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Replace only one character in string.

    So for Column A, just do Range("A:A")?

  10. #10
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Replace only one character in string.

    just columns(1) or columns("a")

  11. #11
    Registered User
    Join Date
    12-29-2011
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Replace only one character in string.

    Thank you!

+ 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