vba help - Number format for blank cell want dash

Mallesh23

Well-known Member
Joined
Feb 4, 2009
Messages
976
Office Version
  1. 2010
Platform
  1. Windows
Hi Team,

Need your help in applying format, if there are blank add dash.

Below attempted code which only covers positive and negative nos. not blank cells

VBA Code:
Sub test()
Range("A2:A6").NumberFormat = "#,#.00"
End Sub

Below is a table with expected output in Column C.

Book10
ABC
1Raw DataExpected
250005,000.00
3100100.00
4-4000-4,000.00
5-
61800018,000.00
Sheet1



Thanks
mg
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
=IF(C2="","-",C2)

This would give you the outcome you are after although I do not know what else it is you have running or why.
 
Upvote 0
If you just format the cells to the desired format then you can just run an "IF" formula and keep everything very simple and easy to modify for yourself.

Below is just using the standard "general" format in the worksheet, as soon as the raw data is entered then your expected will auto fill, this will also let you add in helper cells to add or subtract further.

1601516196575.png
 
Upvote 0
If you set the cell format to accounting without a symbol, Excel will automatically convert 0 to dash. So, this is another option - convert blank to zero.
 
Upvote 0
Hi Yku and Philips,

Thanks for your help, will check and test.

I found below in Custom Format.........

_ * #,##0_ ;_ * -#,##0_ ;_ * "-"??_ ;_ @_


Thanks
mg
 
Upvote 0
Just FYI, a number format can never alter the appearance of an empty cell. It can only change the appearance of actual cell content.
 
Upvote 0
Hi Rory,

Custom Format. shows below formating..
_ * #,##0.00_ ;_ * -#,##0.00_ ;_ * "-"??_ ;_ @_


Range("c1:c100").NumberFormat = "_ * #,##0.00_ ;_ * -#,##0.00_ ;_ * ""-""??_ ;_ @_"
But if I use above custom format in VBA , Getting Error Message "Unable to set number format property.




1601548557128.png




Thanks
mg
 
Upvote 0
You missed a space off the end of the format string:

Code:
Range("c1:c100").NumberFormat = "_ * #,##0.00_ ;_ * -#,##0.00_ ;_ * ""-""??_ ;_ @_ "
 
Upvote 0

Forum statistics

Threads
1,215,200
Messages
6,123,604
Members
449,109
Latest member
Sebas8956

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