Don't display leading zeros when formatting

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,885
Office Version
  1. 365
Platform
  1. Windows
Hi Folks

I think this should be simple, but I've been on this project all day, and am getting tired...

I wish to format numbers into columns, and when displaying them ensure that they all line up.
I'm using a £ symbol, then wish to have leading spaces where there are no numbers, so that the £ symbol is always in the same place, as is the decimal point, and the trailing two numbers. Max leading digits will be thousands.
eg:

45.87 displays as.£&&45.87
145.87 as...........£&145.87
2,145.87 as.........£2145.87

(edit) I've had to use the ampersand symbol to indicate where the spaces should be, as the BBcode strips them out otherwise.

I've searched for hours, and tried using "$", "@", "?" but can't seem to get it to work.

Any help appreciated.........
 
Last edited:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi Brian Thanks for the reply

format(45.6,"Accounting") gave me:
A13/02/1900 14:24:0013/02/1900 14:24:00ou24ti24g
 
Upvote 0
I think the suggestion was to format the cells, rather than use the VBA Format function.
 
Upvote 0
Folks

I didn't specify that it's a string I'm formatting - to write to a label, or text file, not a value in a cell.

Sorry for that!
 
Upvote 0
Code:
Sub x()
    Dim s As String
    Dim v As Variant
 
    For Each v In Array(45.87, 145.87, 2145.87)
        s = Space(10)
        RSet s = Format(v, "0.00")
        Mid(s, 1) = "$"
        Debug.Print s
    Next v
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,508
Messages
6,179,188
Members
452,893
Latest member
denay

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