This article was previously published under Q64681
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
The following macro command will convert a numeric value in the active cellto a text string:
For example, when you run this command on a cell that contains thefollowing entry:
the entry is converted to the following:
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The follow macro example converts either a single cell or a range of cellsfrom numeric data to text so that you can affect multiple cells at onetime.
You can assign this macro to a button in Microsoft Excel version 4.0 byusing the following steps:
From the Options menu, choose Toolbars.
Choose the Customize button.
From the Categories list, select Custom.
From the list of buttons, drag the button that you want to use to run the macro to the toolbar area.
From the Assign Macro list in the Assign To Tool dialog box, select Macro1!Convert_number_to_text (where Macro1 is the macro sheet that contains the macro, and choose OK.
Close the Customize dialog box.
Save the macro sheet, Macro1 in this example, to the XLSTART subdirectory (Windows) or the EXCEL STARTUP FOLDER (4) (Macintosh).
After you save the file, choose Hide from the Window menu to hide the macro sheet. When you exit Microsoft Excel, choose Yes to save the changes to the macro sheet.
The macro sheet will automatically open when you start Microsoft Excel, sothat you can run the macro from the custom toolbar button that you created.
Microsoft Excel Versions 5.0 and later
NOTE: This macro command also applies to Microsoft Excel versions 5.0 and7.0, but is not required, because of the ability to format cells as text.To format cells as text in Microsoft Excel version 5.0 and 7.0, do thefollowing:
Select the cell(s) that you want to format as text.
On the Format menu, click Cells. Select the Number tab.
In the Category list, click Text, and then click OK.
Numbers that you enter in these cell(s) will be formatted as text.
NOTE: If you format a cell as Text in Microsoft Excel versions 5.0 and 7.0,the underlying cell value will still be treated as a number, if that iswhat you entered in the cell. The following Visual Basic for Applicationsmacro will convert underlying cell values to Text.
Sub Convert2Text() For Each Cell in Selection.Cells OldNF$ = Cell.NumberFormat Cell.NumberFormat = "@" Cell.Value = Application.Text(Cell.Value, OldNF$) Next End Sub
To use this macro, select the range of cells you want converted to text andthen run the macro.