Written by Allen Wyatt (last updated July 23, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365
Stuart uses the NumberFormat property, in a macro, to set the custom format for a cell. He sets it equal to #,##0.00_);[Red](#,##0.00), but when he later looks at it, Excel changes the format to #,##0.00;[Red]-#,##0.00.
You can set the custom format of a selection of cells in this manner:
Sub SetCells() Selection.NumberFormat = "#,##0.00_);[Red](#,##0.00)" End Sub
Similarly, you could set the custom format of a specific range of cells in this manner:
Sub SetCells() Range("A1").NumberFormat = "#,##0.00_);[Red](#,##0.00)" End Sub
Either approach sets the custom format correctly, as confirmed through testing. If the format doesn't appear as expected (and you are sure the format pattern matches what is shown above), then there are only two reasons I can think of that would cause the discrepancy. First, it is possible that other macro code is changing the custom format without your knowledge, particularly code in an event handler. Why an event handler? Because event handlers often make changes automatically, typically after cell changes or even moving from one cell to another.
The second possibility is that what you are seeing in the worksheet is not the result of the custom format, but actually the result of a conditional format. You'll need to check and possibly change the conditional formatting rules to deal with this possibility.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12941) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365.
Program Successfully in Excel! This guide will provide you with all the information you need to automate any task in Excel and save time and effort. Learn how to extend Excel's functionality with VBA to create solutions not possible with the standard features. Includes latest information for Excel 2024 and Microsoft 365. Check out Mastering Excel VBA Programming today!
Want to apply a custom format to your dates and times? To do it effectively you need to understand the custom formatting ...
Discover MoreWhen working with very large numbers in a worksheet, you may want the numbers to appear in a shortened notation, with an ...
Discover MoreExcel, by default, displays numbers with a leading zero, if they are less than 1. Here's how you can get rid of those ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments