Changing Number format in VBA message Box

jumbo99

New Member
Joined
Sep 16, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I have a message box in VBA which displays the variable "cash". I am using the "currency" format as below:

cash = Format(cash, "currency")

The problem is that if the amount goes over £10000 it does not put a comma after the first zero (£10,000) to make it clearer to read. I have tried every combination of #,0 etc to make a custom format but it still does not
show a comma after the first zero.

Any ideas.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi & welcome to MrExcel.
Is the variable "cash" declared, if so as what?
 
Upvote 0
Either of the following is working for me:

msgbox format("10000","currency")
msgbox format(10000,"currency")

I tested also in a sub (Cash as Variant, Currency, String), assigning the value 10000 and/or "10000".

Can you post more of the code please?
 
Upvote 0
If it's not declared it should work, otherwise you would need to declare it as variant, or just format the variable when you display the msgbox.
 
Upvote 0
I have just tried creating a new sheet and it works, giving me a comma after the first zero. So it must be something with my very large first sheet. Any ideas. Thanks.
 
Upvote 0
Any ideas. Thanks.
Not really without knowing how you assigned a value to it. Although one possibility is that you are assigning a text value, rather than a number.
 
Upvote 0
Here is the code when I was trying with the #,0 etc:

For Each cell In Range("B1:B143")

If (cell.Value = "CGAR") Or (cell.Value = "CGT") Or (cell.Value = "PNL") Or (cell.Value = "VLS20") Or (cell.Value = "VLS40") Then safetyfunds = safetyfunds + cell.Offset(0, 5).Value
If (cell.Value = "CASH") Then cash = cash + cell.Offset(0, 5).Value
Next cell

' cash = Format(cash, "Currency")
MsgBox "Safety Funds (CGT, CGAR, VLS40 and VLS 20 : " & Format(safetyfunds, "£#,000.00" & vbNewLine & vbNewLine & "Cash: " & Format(cash, "£#,000.00"))
 
Upvote 0
You have a bracket in the wrong place, it should be
VBA Code:
MsgBox "Safety Funds (CGT, CGAR, VLS40 and VLS 20 : " & Format(safetyfunds, "£#,000.00") & vbNewLine & vbNewLine & "Cash: " & Format(cash, "£#,000.00")
 
Upvote 0
Solution

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

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