Number Format in VBA

dave8

Active Member
Joined
Jul 8, 2007
Messages
275
How can I display a number as 123.45 to 123. If number is 123.50, display as 124. I just want to display whole number.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
If you format your cells as Numbers and select 0 decimal places, the numbers will display as you desire!!

lenze
 
Upvote 0
Thanks. But there's something else. An example of my cell looks something like this:

Cost $xxxx ----- I want to look -----> Cost $ - if no value (or zero).

In your suggestion, changing to Number format with 0, looks like this:

Cost $ 0


Note: The title 'Cost' is in cell A1 and $xxxx is in B1.
 
Upvote 0
In your suggestion, changing to Number format with 0, looks like this:

Cost $ 0
Then use a Custom Format
Code:
##;-##;
Actually, with a Custom Format, you only need 1 cell
Code:
"Cost" ##;"Cost" (##);
You can use either a negative sign or parens for your negative values
If you want the dash for zero
Code:
##;-##;-
or
Code:
"Cost" ##;"Cost" (##);-
lenze
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top