+ Reply to Thread
Results 1 to 9 of 9

Add character to string in a cell

  1. #1
    Forum Contributor
    Join Date
    03-03-2011
    Location
    Ottawa, Ontario
    MS-Off Ver
    365
    Posts
    137

    Add character to string in a cell

    I have column B with varying amounts of rows that I need to add a character to the beginning of the string and another character to the string 3 places in the string. Hoping for some vba code loop to accomplish this.

    eg. 12345678 would become x12x345678

    have tried various things but nothing comes out the way I was hoping.
    Thanks for any help

  2. #2
    Forum Contributor
    Join Date
    08-22-2011
    Location
    Texas, United States
    MS-Off Ver
    Excel 2007 and 2010
    Posts
    516

    Re: Add character to string in a cell

    you don't have to use VBA for this, you can use this formula

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Regards,
    amotto

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Add character to string in a cell

    1) In an adjacent empty column, enter this formula,
    ="x" & LEFT(B2, 2) & "x" & MID(B2, 3, LEN(B2))


    2) Copy down the data set

    3) Copy the new column and PAST SPECIAL > VALUES over the original column B.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    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
    49,443

    Re: Add character to string in a cell

    Please Login or Register  to view this content.

    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


  5. #5
    Forum Contributor
    Join Date
    03-03-2011
    Location
    Ottawa, Ontario
    MS-Off Ver
    365
    Posts
    137

    Re: Add character to string in a cell

    I will need VBA as it will be part of a larger macro that is formatting a set of numbers that has been pasted into that column.

  6. #6
    Forum Contributor
    Join Date
    08-22-2011
    Location
    Texas, United States
    MS-Off Ver
    Excel 2007 and 2010
    Posts
    516

    Re: Add character to string in a cell

    If that is the case, then TMS's solution should work. In the future, if you are unsure of how to create a macro, then just record yourself doing the action and you will have it saved. This is a big help to learning VBA.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Add character to string in a cell

    For a VBA solution, worksheet formulas are often faster than line by line editing in a loop, I would recommend the original solution, but in VBA form:

    Please Login or Register  to view this content.

  8. #8
    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
    49,443

    Re: Add character to string in a cell

    Please Login or Register  to view this content.

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Add character to string in a cell

    If it's a fixed format you can just use the numberformat

    Select any cell
    Enter 1234567890

    run the macro below

    Please Login or Register  to view this content.
    The result: 00x001x2345x7890

    You can use any character except d m y becasue then it's translated to day month or year

    And of course you can do it by simply selecting the cell or cells and changing the format, select Number and then custom end type the 00x000x00000x0000
    Last edited by Keebellah; 10-16-2015 at 04:38 PM. Reason: extra info
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

+ 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. How to use cell reference to match character string
    By shanteshmnnit in forum Excel General
    Replies: 6
    Last Post: 05-07-2015, 10:52 AM
  2. UDF to find character in string and reference another cell
    By SoothSailor in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-28-2014, 08:25 PM
  3. [SOLVED] replace nth occurrences of a character string within a cell...
    By herbie226 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-09-2014, 02:50 AM
  4. [SOLVED] find the character position in a string of the last occurrence of a nominated character
    By jmac1947 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-04-2014, 11:52 PM
  5. [SOLVED] Check if each cell contains Initials of MyString after specific character in cell string
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-12-2012, 09:45 PM
  6. Replies: 4
    Last Post: 01-17-2011, 11:44 PM
  7. Replies: 3
    Last Post: 02-02-2006, 01:45 PM

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