vba help - Number format

Mallesh23

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

I am using someones code for converting amounts column into Accounting format.

Are there any other way to get output with simple code.

this is very lengthy :=> "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"

VBA Code:
Sub Convert_Numberformat()
Range("C2:C15").NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"

End Sub

Column A is input Data and Column C and E is expected output. with decimal and without decimal

Book4
ABCDE
1AmountExpected with DecimalExpected without decimal
2294376 2,94,376.00 2,94,376
3767364 7,67,364.00 7,67,364
41378453 13,78,453.00 13,78,453
51421642 14,21,642.00 14,21,642
6801295 8,01,295.00 8,01,295
7964148 9,64,148.00 9,64,148
8427503 4,27,503.00 4,27,503
9158313 1,58,313.00 1,58,313
10871476 8,71,476.00 8,71,476
111389822 13,89,822.00 13,89,822
121020023 10,20,023.00 10,20,023
131057490 10,57,490.00 10,57,490
14777667 7,77,667.00 7,77,667
Sheet1



Thanks
mg
 

Some videos you may like

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,022
Office Version
  1. 2016
Platform
  1. Windows
VBA Code:
Sub Convert_Numberformat()
Range("C2:C15").NumberFormat = "#,#.00"
End Sub
 

Mallesh23

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

Thanks for your help, The code is working , giving correct output.

With decimal :=>Range("C2:C15").NumberFormat = "#,#.00"
Without decimal :=>Range("C2:C15").NumberFormat = "#,#"

What will be the code if I want Negative Number to be surrounded by bracket.
instead of negative symbol.


Thanks
mg
 

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,022
Office Version
  1. 2016
Platform
  1. Windows
Hi MG,

This will turn the negative numbers surrounded by brackets
VBA Code:
Sub Convert_Numberformat()
Range("C2:C15").NumberFormat = "#,#.00;(#,#.00)"
End Sub


If you want the negative numbers to turn red besides being surrounded by brackets
VBA Code:
Sub Convert_Numberformat()
Range("C2:C15").NumberFormat = "#,#.00;[RED](#,#.00)"
End Sub


Regards,

Humayun
 

Mallesh23

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

Thanks for your help. its working.


Thanks
mg
 

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,022
Office Version
  1. 2016
Platform
  1. Windows
Welcome friend
Thanks for the feedback
Take Care
 

Watch MrExcel Video

Forum statistics

Threads
1,122,569
Messages
5,596,912
Members
414,110
Latest member
docops

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
Top