Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditionall format a range of cells depending on call's value

Status
Not open for further replies.

mercenguk

Programmer
Dec 1, 2006
8
GB
Hi,

I have an Excel 2003 spreadsheet which has been created by exporting data from a Delphi application.

I have written a macro to format the output (change column widths, add colours etc) and this is working fine.

However, I need to format a range of cells containing numbers such that if the value in the cell is > 0, the format will be "#,###.00". Otherwise, I need to display the value as 0 ie with no decimal places.

Is it possibe to use code similar to Selection.FormatConditions.Add....(something) in order to correctly format the cells?

Many thanks,

Merceng
 
you don't need vba, look at format, conditional formatting.

macro record will then be your friend again.

mr s. <;)

 
should have read your post.

set the format of the cell (Cell.NumberFormat) to be "#,###.00;-#,###.00;0".

mr s. <;)

 
Applying something like;

.NumberFormat = "#,##0.00;""zero"";""zero"""

to the Cells in question may do it for you.
 
Many thanks to both of you for replying so quickly!

I have applied the formatting you suggested and it works a treat.

Thanks for your help.

Regards,

Merceng
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top