+ Reply to Thread
Results 1 to 6 of 6

Add prefix to number

  1. #1
    Registered User
    Join Date
    02-01-2010
    Location
    england
    MS-Off Ver
    Excel 2003
    Posts
    11

    Add prefix to number

    Hello All

    Can Any 1 tell me how to do the following

    I want to type a number into a cell and then auto add a prefix letter to it.

    I can't use the cell format route as I am using the sumif latter in the sheet and it wont work with a formatted cell

    Any Help ?

    Thanks

  2. #2
    Valued Forum Contributor jj72uk's Avatar
    Join Date
    03-22-2008
    Location
    Essex, England
    MS-Off Ver
    Work - Office 2000, Home - Office 2007E
    Posts
    360

    Re: Add prefix to number

    Will it be the same prefix all the way through?

  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 prefix to number

    This is a way to add the prefix "XX" to the start of any numeric value typed anywhere in column A:

    Please Login or Register  to view this content.

    This is a sheet-level macro.

    1) Right-click on the sheet tab
    2) Select VIEW CODE
    3) Paste in the code (given above)
    4) Exit the VBEditor
    5) Save your workbook as a macro-enabled workbook.

    Now enter a numeric value in column A...
    _________________
    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
    Valued Forum Contributor jj72uk's Avatar
    Join Date
    03-22-2008
    Location
    Essex, England
    MS-Off Ver
    Work - Office 2000, Home - Office 2007E
    Posts
    360

    Re: Add prefix to number

    Reason why I was asking if it was to be the same prefix is becasue there are a few ways.

    A macro is one.

    Or you can format the cell using a custom format of XX #

    Where XX is your prefix.

    Or you can have an additioanl colum that sources where you type in and use ="XX " &A1

    Again XX being the prefix and A1 being where you type your number in.

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Add prefix to number

    Possibly
    On the sheet you want to control
    Please Login or Register  to view this content.
    Add to the prefix array as required
    Control the cells you want to prefix using "Intersect" function in the Select Case statement.

    P.S.
    Or you can format the cell using a custom format of XX #
    Is only a display value and could be a problem if you need the prefix for further calcs
    Last edited by Marcol; 02-05-2010 at 10:11 PM. Reason: P.S. Added, then code changed to handle multiple prefixes

  6. #6
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Add prefix to number

    Prompted by JB's post, and some sleep!
    Please Login or Register  to view this content.
    N.B.
    The lines commented out (shown in green) can be uncommented if you need to prefix any string e.g. "Prefix_Test" would result from entering "_Test" in Range("D2:E10"))

+ 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