Note that there are some explanatory texts on larger screens.

plurals
  1. POExcel: Working with named Range.NumberFormat in VBA: "General" vs. "Standard"
    primarykey
    data
    text
    <p>A couple questions about Range.NumberFormat here--hopefully someone has ready answers they can provide, as searching the web is tough with all the generic terms.</p> <p>A little background: I'm trying to eliminate "random" <strong>Error 1004</strong> codes: <strong>Unable to set the NumberFormat property of the Range class</strong> is the message. The error is occurring when I try to set the .NumberFormat of a <em>late-bound</em> object to a named format, mainly working with "General" or "Standard". The object, in 99% of cases is Application.Selection. Also please note, the most common cause of this error--protection on the sheet or workbook--<em>does not apply</em> here.</p> <ol> <li><p>From Excel 2003 to 2007, Microsoft would appear to have introduced a bug in VBA. If in the immediate window I type <code>? Selection.NumberFormat</code> and hit Enter, I get "General". If I do the same thing with <em>certain addins</em> (not all, not predictable) running a macro with a breakpoint, I usually get "Standard". What is "Standard"? Where does that come from? I want to pick up a number format from one cell, and drop it on another; at random moments, I cannot apply "Standard" in this way, and its result is not like General. (In Excel 2003, it never appears in the immediate window, and fails systematically to apply.)</p></li> <li><p>Even if I convert all instances of "Standard" to "General", I still sometimes get an error on <code>MyObject.NumberFormat = "General"</code>. I have read in a couple of places that one is better off applying the underlying format of the named format, i.e. General applies to something (as I suppose standard does); what is the syntax to do that in Excel VBA?</p></li> </ol> <p>Thanks in advance for your help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload