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: Searching for Leading Apostrophes.

Searching for Leading Apostrophes

Written by Allen Wyatt (last updated January 12, 2021)
This tip applies to Excel 97, 2000, 2002, and 2003


3

Richard would like to be able to search for an apostrophe (') in the leftmost position in a cell, but Excel won't let him do it. In other words, if a cell contains '123 or 'a34tp, Richard would like to be able to find that leading apostrophe and, optionally, replace it with something else.

Doing what Richard wants to do takes a bit of preliminary explaining. Technically, it is a misnomer to refer to the apostrophe as a "leading character" or mentioning that it is in the "leftmost position" of a cell. Even though you may be able to look at the Formula bar and see the apostrophe at the beginning of the formula, that apostrophe is not really a part of the cell's contents; that is why you can't use Find and Replace to find and replace it.

The apostrophe is actually considered a "prefix character" for a cell. The possible values of the prefix character are set by the Transition Navigation Keys setting in Excel, and the value of the setting is saved on a workbook-by-workbook basis. You can change this setting by using the Transition tab of the Options dialog box.

If the setting is cleared (the default condition for the setting), then the value of the prefix character for each cell can either be blank or an apostrophe. If the cell contains text, then the setting of the prefix character doesn't really matter much. If the cell contents are not text, then setting the prefix character to an apostrophe forces Excel to treat the cell contents as if they are text. So, for instance, the number 123 is treated as text—not a number—and shows up in the Formula bar as '123.

If the Transition Navigation Keys setting is selected (the check box has a check mark in it), then the value of the prefix character for each cell can have one of five different values. These values are consistent with the prefixes used in Lotus 1-2-3 and are, oddly enough, supported in Excel only as a transitional aid to the regular usage in the program. The possible values are an apostrophe (left-justified), quote mark (right-justified), carat (centered), back slash (repeated), or blank (non-text item).

Now, back to Richard's original question: how to search and get rid of that leading apostrophe. You can't use Find and Replace to do the editing because the apostrophe isn't really part of the cell contents. So, you must do the changing in a macro. The changing is relatively easy. First, you'll want to make sure that the workbook has the Transition Navigation Keys setting cleared. Why? Because you probably don't want to mess up the prefix character for the cells if the workbook could be used at some future point with Lotus 1-2-3 again. You make sure that the setting is correct, in your macro, with the following line:

Application.TransitionNavigKeys = False

You can then step through a selection of cells and check to see if the prefix character for each cell is an apostrophe. If it is, then all you need to do is have the macro do the equivalent of manually retyping the contents of the cell, in the following manner:

For Each c In Selection
    If c.PrefixCharacter = "'" Then
        c.Value = c.Value
    End If
Next c

Note that the macro checks what is in the PrefixCharacter property. This property can be read in VBA, but it cannot be changed directly. That is why the macro needs to use the seemingly simple line to assign the value of each cell back into the cell—essentially retyping the contents.

If you would rather not use a macro to get rid of the apostrophe prefix characters, then you can take advantage of a strange little quirk of Paste Special. Follow these general steps:

  1. Select a blank cell and copy it to the Clipboard (use Ctrl+C).
  2. Select the range of cells from which you want to remove the prefix character.
  3. Display the Paste Special dialog box.
  4. Click the Add radio button.
  5. Click OK.

After the "adding" of the blank cell to each of the target cells, the prefix character—if any—is removed.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3332) 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: Searching for Leading Apostrophes.

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. ...

MORE FROM ALLEN

Synchronized Workbook and Worksheet Names

When you work on older workbooks in Excel, you may notice that the name of the worksheet tab and the workbook itself are ...

Discover More

Copying a Range of Pages in a Macro

Do you need to copy, within a macro, a range of pages? Because pages can be so fluid in Word, this can be a bit tricky. ...

Discover More

Filling a Drawing Object

Want to add some spice to the graphics in your worksheets? There are many colors and effects in Excel that allow you take ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (menu)

Limiting Searching to a Column

When you use Find and Replace, Excel normally looks through all the cells in a worksheet. You may want to limit the ...

Discover More

Finding and Replacing in Text Boxes

Finding and replacing information in a worksheet is easy. Finding and replacing in other objects (such as text boxes or ...

Discover More

Making All Occurrences Bold

Want to make instances of a given word or phrase bold throughout a worksheet? Here's a way you can make the change quickly.

Discover More
Subscribe

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

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}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. 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 nine minus 5?

2022-01-30 11:32:08

ionut

I wanted just to eliminate those apostrophs signs, I have copied the text into a text file and pasted back into Excel. The apostroph are gone.


2018-08-31 16:58:30

Brian

Thank you for this trick - it saved me a lot of time recently. However, today I tried doing it, and Excel now adds an apostrophe prefix to the cell contents after the 2nd step (replacing = with #= ; Excel now replaces it with '#= ). Any idea what might have caused this change in behavior?


2018-01-23 16:14:46

Bob

Allen,

Thank you for this solution. It is exactly what I needed to save me several minutes of work today. I am grateful to you for your ongoing support of the Excel community. I had been a long-time subscriber to your weekly newsletter, but in these waning years of my current situation, I'm cutting back on some of the inbox load and kind of limiting my self to communications from the Treacys and Jon Acampora. That doesn't mean, however, that I haven't benefited from your efforts and today was a reminder of that. Thanks and I wish you well, sir.


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

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.