+ Reply to Thread
Results 1 to 10 of 10

Replacing the first part of a cell with a different value

  1. #1
    Forum Contributor
    Join Date
    03-20-2013
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    200

    Replacing the first part of a cell with a different value

    Hi,

    I would like a macro to replace the first 3 digits of a cell depending on the value, with 2 digits.

    i have a list of account numbers where the first 3 digits need to be changed depending on what account they are for
    example -

    802-123456, 802 refers to the area,
    803-123465, 803 refers to the area,

    then i have a list of 2 digits that refer to the area, that i need to use
    example -
    802-123456, the area code for that i need to use is 25 so i need the macro to run through column a
    and replace the 802 with 25, so it would read 25-123456

    then for 803, i need the 803 replacing with 26 and so forth

    Please could someone point me in the right direction in acheiving this.

    Many Thanks

  2. #2
    Forum Contributor
    Join Date
    03-20-2013
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Replacing the first part of a cell with a different value

    Anyone help with the above?ty

  3. #3
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Replacing the first part of a cell with a different value

    Hi papasmurfuo9,
    maybe something like this
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    03-20-2013
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Replacing the first part of a cell with a different value

    seems to work perfectly thank you.

  5. #5
    Forum Contributor
    Join Date
    03-20-2013
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Replacing the first part of a cell with a different value

    Hi Nilem
    one little problem, if the 802, is in the account number, example 802123802, it will replace the 802 at the end too, is there any way to get it to just look at the first 3 digits?

    thank you

  6. #6
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Replacing the first part of a cell with a different value

    in your example was 802-, and it is replaced by 25-
    or show an example of a file with the options on the account number

  7. #7
    Forum Contributor
    Join Date
    03-20-2013
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Replacing the first part of a cell with a different value

    Yes sorry i was just trying to make it more clearer in my explanation
    there is no "-" so it would read 802123456
    your code works perfect in replacing the 802, into the correct number for me
    but if by chance the account number has another "802" somewhere in it, it replaces that too
    i would like if possible to just change the first 3 digits of the cell, and ignore the rest.
    this possible?
    thank you.

    my code is now

    Please Login or Register  to view this content.

  8. #8
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Replacing the first part of a cell with a different value

    If you do not have a lot of data, you can try so
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    03-20-2013
    Location
    Manchester
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Replacing the first part of a cell with a different value

    great - thank you.

  10. #10
    Registered User
    Join Date
    08-20-2012
    Location
    Londonish, England
    MS-Off Ver
    Excel 2010
    Posts
    58

    Re: Replacing the first part of a cell with a different value

    Just thought I'd add something else into the mix papasmurfu09 - you could also use the left and right features in a loop if the account numbers will always stay the same amount of characters, so something like:

    Please Login or Register  to view this content.
    Could probably work for you too, it looks for the first three characters and replaces them with whatever you want to replace it with and then adds the last 6 characters that need to stay in there to create the final number.

    Should just point out I didn't have time to enter all of your values but you will just need to add in the additional else ifs etc.

    Thanks

    Chriz
    Last edited by Chriz; 07-31-2013 at 04:06 AM.

+ 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. Replacing part of text in cell
    By Rhudi in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-03-2013, 04:42 PM
  2. [SOLVED] Replacing part of a string with a value of cell for each row
    By diamanthian in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-21-2013, 04:26 PM
  3. Replacing part of a string based on value of another cell?
    By fmushtaq in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-21-2010, 11:44 AM
  4. Replacing Specific part in a cell
    By sjanaswamy in forum Excel General
    Replies: 1
    Last Post: 08-23-2006, 04:26 PM
  5. Replacing part of a cell text
    By oOpsy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-01-2005, 10:54 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