Solved

Add a leading zero to number cells in Excel

Posted on 2013-01-31
2
449 Views
Last Modified: 2013-02-01
Hi - I want to automatically add just one leading zero to number cells in Excel through formatting.

E.g. 6 should be 06, 97 should be 097 and 125 should be 0125.

Thanks.
0
Comment
Question by:paulmac110
2 Comments
 
LVL 92

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 250 total points
ID: 38839225
The easiest way would be to just use a formula to add the leading zero and return it as text:

="0"&A2

If you can guarantee that the biggest number in that column will be less than 1000, you could use this custom number format:

[<10]00;[<100]000;0000

To get fancier than that, you are going to need VBA, probably an event sub on the Change or Calculate events to apply number formatting on a cell-by-cell basis, which I do not recommend.
0
 
LVL 70

Accepted Solution

by:
KCTS earned 250 total points
ID: 38839617
Why not just use formatting

Select the cells, then Use Format Cells->Custom and enter the custom format "0000"
this forces all cells to have four digits - leading zeros will be added as appropriate
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you how to use shortcut menus in the Access run-time environment.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question