Excel: Keeping Formats when Changing Numbers to Text in MacroLast reviewed: November 3, 1994Article ID: Q79191 |
The information in this article applies to:
SUMMARYNumbers in a worksheet or macro sheet can be converted to text while automatically maintaining the existing number format by using the command macro described below.
MORE INFORMATIONThe macro statement shown below will replace the number in the active cell with its text equivalent, while retaining the original number format.
=FORMULA(CHAR(61)&CHAR(34)&TEXT(ACTIVE.CELL(), IF(GET.CELL(7)="General","#",GET.CELL(7)))&CHAR(34))Normally, using the TEXT function within the FORMULA function will cause the text to be converted to a number when placed into a worksheet cell. The above formula first gets the number format, applies the format to the text, and then concatenates an equal sign ("CHAR(61)") and double quotation marks ("CHAR(34)") to the beginning and the end to ensure that the text remains as text. As a result, you do not have to specify a format; the existing number format is applied automatically.
REFERENCES"Microsoft Excel User's Guide," version 3.0, page 113 "Microsoft Excel Function Reference," version 3.0, pages 29, 80, 89-90
|
KBCategory: kbother
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |