Solved

Add a leading zero to number cells in Excel

Posted on 2013-01-31
2
470 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

751 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