Custom Number Formats in Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Hope this qualifies as "programming".

the following macro:

Selection.NumberFormat = "#,##0_);(#,##0)"

does not do the job I was hoping.

On examination the format that is applied is:

#,##0;-#,##0

any way to get my preferred format to "take"?

TIA, Matt
 
Further Developments :-)

Irony of Ironies - this is the example in the Help system:

Example
These examples set the number format for cell A17, row one, and column C
(respectively) on Sheet1.

Worksheets("Sheet1").Range("A17").NumberFormat = "General"
Worksheets("Sheet1").Rows(1).NumberFormat = "hh:mm:ss"
Worksheets("Sheet1").Columns("C"). _
NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"

and this doesn't work either!

My colleague very helpfully suggested using "Styles" and while this should
be workable this is starting to turn something that should be super-neat and
tidy into something more cumbersome (having to create the style
programmatically before applying it).

So suggestions as to why the simple approach isn't working are still sought.

TIA and Cheers, Matt
 
Excel depends on somethings from windows.

Try changing the negative currency format under windows regional settings (under
control panel) to:
($1.1)

When I changed it to:
-$1.1

I had the same problem as you.

And I had to close excel and reopen to see the difference.
Further Developments :-)

Irony of Ironies - this is the example in the Help system:

Example
These examples set the number format for cell A17, row one, and column C
(respectively) on Sheet1.

Worksheets("Sheet1").Range("A17").NumberFormat = "General"
Worksheets("Sheet1").Rows(1).NumberFormat = "hh:mm:ss"
Worksheets("Sheet1").Columns("C"). _
NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"

and this doesn't work either!

My colleague very helpfully suggested using "Styles" and while this should
be workable this is starting to turn something that should be super-neat and
tidy into something more cumbersome (having to create the style
programmatically before applying it).

So suggestions as to why the simple approach isn't working are still sought.

TIA and Cheers, Matt

veryeavy said:
Hi,

Hope this qualifies as "programming".

the following macro:

Selection.NumberFormat = "#,##0_);(#,##0)"

does not do the job I was hoping.

On examination the format that is applied is:

#,##0;-#,##0

any way to get my preferred format to "take"?

TIA, Matt
 
it works for me.

in a blank worksheet, enter a number in a1 and make sure it's selected
then in the vb editor open the immediate window (view/immediate window or
ctrl-G)

then paste your code in there, place your cursor on the line of code and hit
enter: Selection.NumberFormat = "#,##0_);(#,##0)"

does it format your number correctly?
 
You may not have to close Excel and reopen--I may have not hit the Apply button
(oopsie!).
Further Developments :-)

Irony of Ironies - this is the example in the Help system:

Example
These examples set the number format for cell A17, row one, and column C
(respectively) on Sheet1.

Worksheets("Sheet1").Range("A17").NumberFormat = "General"
Worksheets("Sheet1").Rows(1).NumberFormat = "hh:mm:ss"
Worksheets("Sheet1").Columns("C"). _
NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"

and this doesn't work either!

My colleague very helpfully suggested using "Styles" and while this should
be workable this is starting to turn something that should be super-neat and
tidy into something more cumbersome (having to create the style
programmatically before applying it).

So suggestions as to why the simple approach isn't working are still sought.

TIA and Cheers, Matt

veryeavy said:
Hi,

Hope this qualifies as "programming".

the following macro:

Selection.NumberFormat = "#,##0_);(#,##0)"

does not do the job I was hoping.

On examination the format that is applied is:

#,##0;-#,##0

any way to get my preferred format to "take"?

TIA, Matt
 
No.

Can I expect to get differing results via the immediate window rather than
the macro? This is quite literally a one line macro so I wouldn't have
expected a different result ...

Was worth a try tho' :-)

Thx
 
Hi Dave,

I don't seem to have a specific negative currency option.

My Options are Number: and Currency:

and are set to:

123,456,789.00 and $123,456,789.00 respectively.

I am running Excel 2003 SP1 on Windows XP Professional SP2.

TIAA :-)

Matt

Dave Peterson said:
Excel depends on somethings from windows.

Try changing the negative currency format under windows regional settings (under
control panel) to:
($1.1)

When I changed it to:
-$1.1

I had the same problem as you.

And I had to close excel and reopen to see the difference.
Further Developments :-)

Irony of Ironies - this is the example in the Help system:

Example
These examples set the number format for cell A17, row one, and column C
(respectively) on Sheet1.

Worksheets("Sheet1").Range("A17").NumberFormat = "General"
Worksheets("Sheet1").Rows(1).NumberFormat = "hh:mm:ss"
Worksheets("Sheet1").Columns("C"). _
NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"

and this doesn't work either!

My colleague very helpfully suggested using "Styles" and while this should
be workable this is starting to turn something that should be super-neat and
tidy into something more cumbersome (having to create the style
programmatically before applying it).

So suggestions as to why the simple approach isn't working are still sought.

TIA and Cheers, Matt

veryeavy said:
Hi,

Hope this qualifies as "programming".

the following macro:

Selection.NumberFormat = "#,##0_);(#,##0)"

does not do the job I was hoping.

On examination the format that is applied is:

#,##0;-#,##0

any way to get my preferred format to "take"?

TIA, Matt
 
Your code worked fine for me also.
Does this small code help in debugging.
It returns the current format, what it should be, and what it was changed
to.

Sub Test()
Const s As String = "#,##0_);(#,##0)"

Debug.Print Range("A1").NumberFormat
Range("A1").NumberFormat = s

Debug.Print s
Debug.Print Range("A1").NumberFormat
End Sub

For me, it returned:

General
#,##0_);(#,##0)
#,##0_);(#,##0)
 
In WinXP Home, I can get to the Control panel
then Regional and language options
then click the customize button
Hi Dave,

I don't seem to have a specific negative currency option.

My Options are Number: and Currency:

and are set to:

123,456,789.00 and $123,456,789.00 respectively.

I am running Excel 2003 SP1 on Windows XP Professional SP2.

TIAA :-)

Matt

Dave Peterson said:
Excel depends on somethings from windows.

Try changing the negative currency format under windows regional settings (under
control panel) to:
($1.1)

When I changed it to:
-$1.1

I had the same problem as you.

And I had to close excel and reopen to see the difference.
Further Developments :-)

Irony of Ironies - this is the example in the Help system:

Example
These examples set the number format for cell A17, row one, and column C
(respectively) on Sheet1.

Worksheets("Sheet1").Range("A17").NumberFormat = "General"
Worksheets("Sheet1").Rows(1).NumberFormat = "hh:mm:ss"
Worksheets("Sheet1").Columns("C"). _
NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"

and this doesn't work either!

My colleague very helpfully suggested using "Styles" and while this should
be workable this is starting to turn something that should be super-neat and
tidy into something more cumbersome (having to create the style
programmatically before applying it).

So suggestions as to why the simple approach isn't working are still sought.

TIA and Cheers, Matt

:

Hi,

Hope this qualifies as "programming".

the following macro:

Selection.NumberFormat = "#,##0_);(#,##0)"

does not do the job I was hoping.

On examination the format that is applied is:

#,##0;-#,##0

any way to get my preferred format to "take"?

TIA, Matt
 
Many Thanks.

Silly Me - didn't look there.

Unfortunately in our drab, bolted down, corporate world we don't seem to be
allowed to change this option ...

Dave Peterson said:
In WinXP Home, I can get to the Control panel
then Regional and language options
then click the customize button
Hi Dave,

I don't seem to have a specific negative currency option.

My Options are Number: and Currency:

and are set to:

123,456,789.00 and $123,456,789.00 respectively.

I am running Excel 2003 SP1 on Windows XP Professional SP2.

TIAA :-)

Matt

Dave Peterson said:
Excel depends on somethings from windows.

Try changing the negative currency format under windows regional settings (under
control panel) to:
($1.1)

When I changed it to:
-$1.1

I had the same problem as you.

And I had to close excel and reopen to see the difference.

veryeavy wrote:

Further Developments :-)

Irony of Ironies - this is the example in the Help system:

Example
These examples set the number format for cell A17, row one, and column C
(respectively) on Sheet1.

Worksheets("Sheet1").Range("A17").NumberFormat = "General"
Worksheets("Sheet1").Rows(1).NumberFormat = "hh:mm:ss"
Worksheets("Sheet1").Columns("C"). _
NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"

and this doesn't work either!

My colleague very helpfully suggested using "Styles" and while this should
be workable this is starting to turn something that should be super-neat and
tidy into something more cumbersome (having to create the style
programmatically before applying it).

So suggestions as to why the simple approach isn't working are still sought.

TIA and Cheers, Matt

:

Hi,

Hope this qualifies as "programming".

the following macro:

Selection.NumberFormat = "#,##0_);(#,##0)"

does not do the job I was hoping.

On examination the format that is applied is:

#,##0;-#,##0

any way to get my preferred format to "take"?

TIA, Matt
 
Maybe you can use a numberformat that's very close to the naked eye--but is
actually different:

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

becomes

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

(with a couple more spaces)

And since it's different than the format that excel/windows uses to collaborate
against you, it may work!
Many Thanks.

Silly Me - didn't look there.

Unfortunately in our drab, bolted down, corporate world we don't seem to be
allowed to change this option ...

Dave Peterson said:
In WinXP Home, I can get to the Control panel
then Regional and language options
then click the customize button
Hi Dave,

I don't seem to have a specific negative currency option.

My Options are Number: and Currency:

and are set to:

123,456,789.00 and $123,456,789.00 respectively.

I am running Excel 2003 SP1 on Windows XP Professional SP2.

TIAA :-)

Matt

:

Excel depends on somethings from windows.

Try changing the negative currency format under windows regional settings (under
control panel) to:
($1.1)

When I changed it to:
-$1.1

I had the same problem as you.

And I had to close excel and reopen to see the difference.

veryeavy wrote:

Further Developments :-)

Irony of Ironies - this is the example in the Help system:

Example
These examples set the number format for cell A17, row one, and column C
(respectively) on Sheet1.

Worksheets("Sheet1").Range("A17").NumberFormat = "General"
Worksheets("Sheet1").Rows(1).NumberFormat = "hh:mm:ss"
Worksheets("Sheet1").Columns("C"). _
NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"

and this doesn't work either!

My colleague very helpfully suggested using "Styles" and while this should
be workable this is starting to turn something that should be super-neat and
tidy into something more cumbersome (having to create the style
programmatically before applying it).

So suggestions as to why the simple approach isn't working are still sought.

TIA and Cheers, Matt

:

Hi,

Hope this qualifies as "programming".

the following macro:

Selection.NumberFormat = "#,##0_);(#,##0)"

does not do the job I was hoping.

On examination the format that is applied is:

#,##0;-#,##0

any way to get my preferred format to "take"?

TIA, Matt
 
Thanks Dana)

Now we are getting somewhere. It does indeed return the "supposed" format
that I have applied.

That leaves the question - Why does using this line of code and using the
"format cells" dialog lead to two different results (as I am presuming this
discounts Dave's helpful suggestion re Settings - thanks Dave!)?
 
A very good trick it is too - thanks Dave - that works.

And yes - I do feel like I have been collaborated over by Excel/Windows - lol.

However one further development is I was wrong earlier (don't ask!) and I
can and have changed the negative number setting to "(1.1)"

And the formatting as I really want it still displays as -1,000 via the
macro and (1,000) via the Format Cells functionality.

Dave Peterson said:
Maybe you can use a numberformat that's very close to the naked eye--but is
actually different:

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

becomes

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

(with a couple more spaces)

And since it's different than the format that excel/windows uses to collaborate
against you, it may work!
Many Thanks.

Silly Me - didn't look there.

Unfortunately in our drab, bolted down, corporate world we don't seem to be
allowed to change this option ...

Dave Peterson said:
In WinXP Home, I can get to the Control panel
then Regional and language options
then click the customize button
On the currency tab, I see "negative currency format" as the 3rd dropdown.


veryeavy wrote:

Hi Dave,

I don't seem to have a specific negative currency option.

My Options are Number: and Currency:

and are set to:

123,456,789.00 and $123,456,789.00 respectively.

I am running Excel 2003 SP1 on Windows XP Professional SP2.

TIAA :-)

Matt

:

Excel depends on somethings from windows.

Try changing the negative currency format under windows regional settings (under
control panel) to:
($1.1)

When I changed it to:
-$1.1

I had the same problem as you.

And I had to close excel and reopen to see the difference.

veryeavy wrote:

Further Developments :-)

Irony of Ironies - this is the example in the Help system:

Example
These examples set the number format for cell A17, row one, and column C
(respectively) on Sheet1.

Worksheets("Sheet1").Range("A17").NumberFormat = "General"
Worksheets("Sheet1").Rows(1).NumberFormat = "hh:mm:ss"
Worksheets("Sheet1").Columns("C"). _
NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"

and this doesn't work either!

My colleague very helpfully suggested using "Styles" and while this should
be workable this is starting to turn something that should be super-neat and
tidy into something more cumbersome (having to create the style
programmatically before applying it).

So suggestions as to why the simple approach isn't working are still sought.

TIA and Cheers, Matt

:

Hi,

Hope this qualifies as "programming".

the following macro:

Selection.NumberFormat = "#,##0_);(#,##0)"

does not do the job I was hoping.

On examination the format that is applied is:

#,##0;-#,##0

any way to get my preferred format to "take"?

TIA, Matt
 
It would be pretty funny if you didn't need to actually use it, huh?

(I have no idea why there's a change.)

A very good trick it is too - thanks Dave - that works.

And yes - I do feel like I have been collaborated over by Excel/Windows - lol.

However one further development is I was wrong earlier (don't ask!) and I
can and have changed the negative number setting to "(1.1)"

And the formatting as I really want it still displays as -1,000 via the
macro and (1,000) via the Format Cells functionality.

Dave Peterson said:
Maybe you can use a numberformat that's very close to the naked eye--but is
actually different:

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

becomes

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

(with a couple more spaces)

And since it's different than the format that excel/windows uses to collaborate
against you, it may work!
Many Thanks.

Silly Me - didn't look there.

Unfortunately in our drab, bolted down, corporate world we don't seem to be
allowed to change this option ...

:

In WinXP Home, I can get to the Control panel
then Regional and language options
then click the customize button
On the currency tab, I see "negative currency format" as the 3rd dropdown.


veryeavy wrote:

Hi Dave,

I don't seem to have a specific negative currency option.

My Options are Number: and Currency:

and are set to:

123,456,789.00 and $123,456,789.00 respectively.

I am running Excel 2003 SP1 on Windows XP Professional SP2.

TIAA :-)

Matt

:

Excel depends on somethings from windows.

Try changing the negative currency format under windows regional settings (under
control panel) to:
($1.1)

When I changed it to:
-$1.1

I had the same problem as you.

And I had to close excel and reopen to see the difference.

veryeavy wrote:

Further Developments :-)

Irony of Ironies - this is the example in the Help system:

Example
These examples set the number format for cell A17, row one, and column C
(respectively) on Sheet1.

Worksheets("Sheet1").Range("A17").NumberFormat = "General"
Worksheets("Sheet1").Rows(1).NumberFormat = "hh:mm:ss"
Worksheets("Sheet1").Columns("C"). _
NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"

and this doesn't work either!

My colleague very helpfully suggested using "Styles" and while this should
be workable this is starting to turn something that should be super-neat and
tidy into something more cumbersome (having to create the style
programmatically before applying it).

So suggestions as to why the simple approach isn't working are still sought.

TIA and Cheers, Matt

:

Hi,

Hope this qualifies as "programming".

the following macro:

Selection.NumberFormat = "#,##0_);(#,##0)"

does not do the job I was hoping.

On examination the format that is applied is:

#,##0;-#,##0

any way to get my preferred format to "take"?

TIA, Matt
 
Right)

And if the format never existed and I never got "addicted" to it and I
wasn't a beanie (accountant) then life would be SWEET ...

Thanks for your help (and everyone else too).

Cheers,

Matt

Dave Peterson said:
It would be pretty funny if you didn't need to actually use it, huh?

(I have no idea why there's a change.)

A very good trick it is too - thanks Dave - that works.

And yes - I do feel like I have been collaborated over by Excel/Windows - lol.

However one further development is I was wrong earlier (don't ask!) and I
can and have changed the negative number setting to "(1.1)"

And the formatting as I really want it still displays as -1,000 via the
macro and (1,000) via the Format Cells functionality.

Dave Peterson said:
Maybe you can use a numberformat that's very close to the naked eye--but is
actually different:

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

becomes

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

(with a couple more spaces)

And since it's different than the format that excel/windows uses to collaborate
against you, it may work!

veryeavy wrote:

Many Thanks.

Silly Me - didn't look there.

Unfortunately in our drab, bolted down, corporate world we don't seem to be
allowed to change this option ...

:

In WinXP Home, I can get to the Control panel
then Regional and language options
then click the customize button
On the currency tab, I see "negative currency format" as the 3rd dropdown.


veryeavy wrote:

Hi Dave,

I don't seem to have a specific negative currency option.

My Options are Number: and Currency:

and are set to:

123,456,789.00 and $123,456,789.00 respectively.

I am running Excel 2003 SP1 on Windows XP Professional SP2.

TIAA :-)

Matt

:

Excel depends on somethings from windows.

Try changing the negative currency format under windows regional settings (under
control panel) to:
($1.1)

When I changed it to:
-$1.1

I had the same problem as you.

And I had to close excel and reopen to see the difference.

veryeavy wrote:

Further Developments :-)

Irony of Ironies - this is the example in the Help system:

Example
These examples set the number format for cell A17, row one, and column C
(respectively) on Sheet1.

Worksheets("Sheet1").Range("A17").NumberFormat = "General"
Worksheets("Sheet1").Rows(1).NumberFormat = "hh:mm:ss"
Worksheets("Sheet1").Columns("C"). _
NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"

and this doesn't work either!

My colleague very helpfully suggested using "Styles" and while this should
be workable this is starting to turn something that should be super-neat and
tidy into something more cumbersome (having to create the style
programmatically before applying it).

So suggestions as to why the simple approach isn't working are still sought.

TIA and Cheers, Matt

:

Hi,

Hope this qualifies as "programming".

the following macro:

Selection.NumberFormat = "#,##0_);(#,##0)"

does not do the job I was hoping.

On examination the format that is applied is:

#,##0;-#,##0

any way to get my preferred format to "take"?

TIA, Matt
 
Back
Top