Solved

Custom Cell Format VIA VBA Macro

Posted on 2011-02-22
2
879 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now