Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Using Find and Replace to Pre-Pend Characters.

Using Find and Replace to Pre-Pend Characters

by Allen Wyatt
(last updated October 27, 2012)


Mel often wants to pre-pend a character to the beginning of whatever is in a range of cells. For instance, he may want to add a letter to the start of some text (so "123" becomes "A123" and "xyz" becomes "Axyz") or he may want to add an apostrophe (so "123" becomes "'123" and "xyz" becomes "'xyz"). Mel wonders if this can be done using Find and Replace.

The short answer is that it cannot. The Find and Replace capabilities in Excel are more limited than those in Word, where you have the capability to search for wildcards and use the "Find What" text in what is replaced. (These are just two examples of capabilities missing in Excel's Find and Replace.)

One potential answer, then, is to copy your data over to Word, use Find and Replace to make the changes, and then copy the data back. Of course, you run the risk of losing your formatting in the round trip, losing some of your precision, and converting all your formula results to static values. For many users, these are not acceptable risks.

Another option is to use the concatenation capabilities of Excel. For instance, if the values you want to pre-pend is in column A (beginning with A1), then you would use a formula such as this is column B:

="A" & A1

The result pre-pends the letter A to whatever is in A1. This works for pre-pending anything except an apostrophe. Trying to pre-pend an apostrophe ends up with '123 or 'xyz, but the apostrophe is visible in the cell. The result is not the same, to Excel, as typing an apostrophe followed by 123 or an apostrophe followed by xyz. (In the case of typing, the apostrophe indicates the cell contents should be treated as text and the apostrophe is only visible in the Formula bar, not in the cell itself.)

If you actually want to change the values in a series of cells (which a desire to use Find and Replace would suggest), then the only thing you can do is to use a macro to make your changes. If you only want to pre-pend cells beginning with a set value (such as 123) with a letter (such as A), then a simple macro will suffice.

Sub Prepend1()
    ToFind = "123"
    ToPrepend = "A"

    For Each rcell In Selection
        If LCase(Mid(rcell.Value, 1, ToFindLength)) =  LCase(ToFind) Then
            rcell.Value = ToPrepend & rcell.Value
        End If
End Sub

Note that the ToFind variable contains the beginning text that you want to pre-pend and the ToPrepend variable contains what you want to appear before that string. In this instance, when you select a range of cells and run the macro, anything beginning with 123 (such as "123" or "12345" or "123D27X") will have the letter A added to the front of the cell.

Such a macro doesn't help, however, when you want to add the letter to the front of every cell in the range, not just those beginning with 123. In that case you need a different approach.

Sub Prepend2()
    Dim rng As Range
    Dim c As Range
    Dim ToPrepend As String

    ToPrepend = "A"

    ' Process only text and number constants
    Set rng = Selection.SpecialCells(xlCellTypeConstants, 3)

    For Each c In rng
        c.Value = ToPrepend & c.Value
    Next c
End Sub

This macro takes a subset of whatever cells you selected before running it (only those cells containing text and numeric values) and then adds the contents of the ToPrepend variable to the start of the cell. If you want to change what is pre-pended, simply change the value of the variable. (It should be noted that if you change ToPrepend to an apostrophe, then the cells to which the apostrophe is pre-pended behave exactly as if you had typed and apostrophe followed by the cell value.)

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3883) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Using Find and Replace to Pre-Pend Characters.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...


Understanding Manual Calculation

When you make changes in a worksheet, Excel automatically recalculates everything that may be affected by that change. If ...

Discover More

Compiling a List of Students in a Course

Need to pull just a limited amount of information from a large list? Here are a few approaches you might be able to use with ...

Discover More

Updating an Entire TOC from a Macro

The TOC (Table of Contents) is generated by a field. This field may be updated in a macro using a single command line.

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!


Changing Default Search Settings

Excel provides some great tools for finding information in a worksheet or a workbook. Changing the default settings used for ...

Discover More

Finding Text in Text Boxes

Want to search for text that may appear in a text box rather than in a regular worksheet cell? You can only perform the ...

Discover More

Find and Replace in Headers

Using Find and Replace is something quite routine in Excel, as it easily allows you to find and replace information in your ...

Discover More

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments for this tip:

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is seven minus 6?

2012-11-21 08:28:16


Great tip sir. I have gone to the trust centre in the excel options in ms excel 2007, and disabled the connections for my computer. But I do not know, how to find the hidden macro , if any, resident sir. When i click the existing connection, there was one connection dated very old.So, i removed all those, and now i did not get the macro warning.

2012-11-19 06:46:24

Barry Fitzpatrick

In all versions of Excel you can bring up the Macro editor (better known as the Visual Basic Editor, VBE) by pressing Alt+F11.

If macros are resident in a Module or Userform then to avoid the macros warning the Module/Userform itself must also be deleted as well as any resident macros.

You could also put the workbook into a "trusted" location and run form there PROVIDED you are completely comfortable that the macros are not harmful.

2012-11-19 05:55:31


Great tip barry sir, This is a perfect point to point practical reply.

2012-11-19 05:53:15


Great tip barry sir, This is a perfect point to point practical reply. By the by, may ask one other sub question.I do not find any macro ( i copied the webcontents to excel , omitting hyperlinks etc). But when i open the excel book, I get the macro warning. How to find the macro in excel 2007 and to delete it? I fear loss of data if i disable the macro,if present. Thank you, sir, once again for this excellent tip. It worked for me. I rate this reply highly and would recommend to be added to the FAQ

2012-11-18 07:54:55

Barry Fitzpatrick


The problem you are seeing is due to the fact the time is stored as an Excel date/time serial number, then the formatting is showing it as a time.

There is a couple of approaches you can take:
1. use custom formatting, and preserve the underlying value as a time value. the easiest way to do this is to open the cell formatting dialog box (Ctrl+1), click on "Custom" then insert "C" to the formatting in the "Type:" box, then click OK;
2. in an adjacent cell converting the time to a text string and prefix the text string with "C". e.g. if the time is in cell A1 the the formula "="C"&Text(A1,"h:mm AM/PM")) will give the desire result. OR
if your using the macros in the tip replace the formula: c.value=ToPrepend &c.value with:
c.value=ToPrepend & Format(c.value,"h:mm AM/PM")

The first method is I believe the best as it preserves the underlying time value.

2012-11-18 04:29:17


When i tried to concatenate the letter "C" with the h:mm format (3:55:00 A.M) the result is not expected A3:55 but C0.163194444444444 . Why? Is there a solution. can this 3:55:00 A.M be made

Newest Tips

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.

Links and Sharing