Leading zeros after a "-"

Harvey12

Board Regular
Joined
Feb 23, 2015
Messages
130
Hi All,

I am trying to display leading zeros after a hyphen.

for example 9999-"0"800.

The zero inside the " " is the issue. I can't seem to find a format to get this zero to be displayed can someone please assist.

Many thanks
Harvey
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
you will have to use split function
Code:
[COLOR=#222222][FONT=Verdana]Sub Testt()[/FONT][/COLOR] 
   Const c As String = "9999-0800"
    Dim s As String
    Dim v As Variant


    s = Replace(c, "-", "#-#", 1)


    v = Split(s, "#-#")


    MsgBox Left(v(1), 1)


End Sub
 
Upvote 0
Hi All,

I am trying to display leading zeros after a hyphen.

for example 9999-"0"800.

The zero inside the " " is the issue. I can't seem to find a format to get this zero to be displayed can someone please assist.
Are those quote marks in you number like you show or is your number 9999-0800?

How is that number formed? Your question makes me think you have concatenated two values together. If so, show us the formula you used to do the concatenation.
 
Last edited:
Upvote 0
Perhaps:

Code:
Sub Test()
Dim t, s As String
t = Split(ActiveCell, "-")
t(1) = Format(t(1), "0000")
ActiveCell = Join(t, "-")
End Sub
 
Upvote 0
Hi All,

thank you for your replies!

So the formulas used are these: =SOURCE!$B2&SOURCE!$D2 this is looking at a separate tab to combine two numbers. that that tab the two numbers look like this:
9831- 0700

but when that is returned in the cell with ( =SOURCE!$B2&SOURCE!$D2 ) they show like: 9831-700...

I can't seem to get a format correct to allow the cell to show the 0
 
Upvote 0
Hi All,

thank you for your replies!

So the formulas used are these: =SOURCE!$B2&SOURCE!$D2 this is looking at a separate tab to combine two numbers. that that tab the two numbers look like this:
9831- 0700

but when that is returned in the cell with ( =SOURCE!$B2&SOURCE!$D2 ) they show like: 9831-700...

I can't seem to get a format correct to allow the cell to show the 0
Try the formula like this...

=SOURCE!$B2&TEXT(SOURCE!$D2,"0000")
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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