Solved

Custom Cell Format VIA VBA Macro

Posted on 2011-02-22
2
891 Views
Last Modified: 2012-06-27
I'm currently using the following as a custom cell format:

"_($* #,##0.00_);[Red]_($* -#,##0.00_);_($* " - "??_);_(@_)"

Instead of right-clicking the cell and setting this format using the cell properties, I would like to set this via a VBA macro.

I have tried
Range("H:K").Select
Range("H:K").FormatConditions = "_($* #,##0.00_);[Red]_($* -#,##0.00_);_($* " - "??_);_(@_)"

Open in new window

or
Selection.NumberFormat = "_($* #,##0.00_);[Red]_($* -#,##0.00_);_($* " - "??_);_(@_)"

Open in new window


But that doesn't work.

Alternatively, I have also tried
Range("H:K").Select
Selection.Style = "Currency"

Open in new window

But that doesn't show negative numbers in red or show the negative sign (it formats with brackets).

Essentially, I would like to format (via vba macro) the range of cells as currency with 2 decimal places, $ sign, comma ($1000) separator and red if negative.

Thanks

0
Comment
Question by:bingie
2 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 500 total points
ID: 34958502
Try:

Range("H:K").NumberFormat = "_($* #,##0.00_);[Red]_($* -#,##0.00_);_($* "" - ""??_);_(@_)"

Kevin
0
 
LVL 11

Author Closing Comment

by:bingie
ID: 34958517
Perfect!

Thanks Kevin!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you how to use shortcut menus in the Access run-time environment.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question