Microsoft Knowledge Base

Incorrect NumberFormat Argument in Recorded Visual Basic Macro

Last reviewed: September 12, 1996
Article ID: Q120360
The information in this article applies to:
  • Microsoft Excel for the Macintosh, version 5.0

SYMPTOMS

In Microsoft Excel, when you turn on the macro recorder, using the Visual Basic language, and you format a cell using a currency number format, the NumberFormat argument is recorded incorrectly.

CAUSE

This behavior only occurs when you apply a number format that contains parentheses, such as the following currency format code:

   $#,##0_);($#,##0)

The following line is recorded when you apply the format code above in a Visual Basic macro:

   Selection.NumberFormat = "$#,##0;-$#,##0"

The parentheses are not included in the recorded format code. Note that when you run the recorded macro, the correct format code is applied to the selected cell, even though the argument appears incorrect in the recorded macro.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The MS Excel Visual Basic Help gives the following example for the NumberFormat property:

   Columns("C").NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"

This syntax works correctly, even though this is not the syntax that is recorded when you apply this format while the macro recorder is running.

REFERENCES

For more information about the NumberFormat Property, choose the Search button in MS Excel Visual Basic Help and type:

   NumberFormat Property


KBCategory: kbprg
KBSubcategory:

Additional reference words: 5.00



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 12, 1996
©1997 Microsoft Corporation. All rights reserved. Legal Notices.