Keep Leading Zeros

Sufiyan97

Well-known Member
Joined
Apr 12, 2019
Messages
1,614
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
is there any way to keep leading zeros while using formula,
length of number is not same for all rows,
also leading zero number is not same for all some have one leading zero some have two and some have three,
is there a way to keep original number while grabbing it with formula?

Book2
BCDEFGHIJ
1Employee NamePriorityBank NameAccount #
2ALEXANDER, ANGELA L1BANK OF AMER 0196000650342558ALEXANDER, ANGELA L650342558
3COWAND, MICHAEL D1BB & T 11210005112406796COWAND, MICHAEL D5112406796
4Williams, Leigh H1CAROLINA TELCO 49770002036349Williams, Leigh H2036349
5
6
7
8
Table 1
Cell Formulas
RangeFormula
H2:H4H2=LEFT(INDEX(E:E,MATCH(G2,B:B,0)),LEN(INDEX(E:E,MATCH(G2,B:B,0))))
 

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"
The numbers in col E do not have leading zeros, that is just a custom cell format.
 
Upvote 0
Just use the same custom format as you have in column E for column H.
 
Upvote 0
Thank you both for looking into it.

I have checked and all cells have different custom format, is there any way to apply same format for each number based on column E?
 
Upvote 0
Thank you both for looking into it.

I have checked and all cells have different custom format, is there any way to apply same format for each number based on column E?
One easy way would be to simply copy the entire column format from column E and apply it to column H.
Just select column E, click on the Copy Format Painter, and then select column H and press enter.

In VBA code, it would simply look like:
VBA Code:
Sub CopyFormattingMacro()

    Columns("E:E").Copy
    Columns("H:H").PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    
End Sub
 
Upvote 0
Thanks Joe, I think what I was looking for has no logic, I was pulling some of the numbers based on name with formula and wanted to appy that format to only formula results.

Thank you again for your time and suggetions.
 
Upvote 0
Thanks Joe, I think what I was looking for has no logic, I was pulling some of the numbers based on name with formula and wanted to appy that format to only formula results.

Thank you again for your time and suggetions.
Note that native Excel functions only run on values. They do not look at the formats of other cells.
Formatting only changes the appearance on the screen for the user - it has no impact on the underlying values in the cells, and that is what native Excel formulas reference.

So, since there appears to be no consistency in the format of column E from cell-to-cell, I really only see two options:
1. Manually copy the formats for the cell/columns, like I explained
2. Use VBA to copy the formats from column E to column H (there are other ways of going about this that may be automated, depending on how data is being updated, and how the updates should be triggered).
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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