Keep Or Delete Leading Zeros In Excel

When you type some numbers in Excel table, you may find that sometimes you need the leading zeros in the numbers but sometimes not. So you may want to make it clear how or keep or delete leading zeros in Excel. Here i would show you.

Keep Leading Zeros With Format Cells

Step 1: When you want to keep leading zeros in a range of cells, you should first select the range of cells and right click to bring up an option list. Last, select the Format Cells option.

select-format-cell-option

Step 2: When the Format Cells dialog pops up, just find the Number tab and choose the Text in the category pane.

select-text-option

Then you can see that the number you have typed in the cells has kept the leading zeros.

keep-leading-zero

Remove the leading zeros in Excel

When you want to remove the leading zeros in Excel table you should follow the under ways.

Way 1: Select the range cells which are filled by numbers with leading zeros, click the warning icon besides the selection, and then select the Convert to Number from the context menu.

convert-to-number

delete-leading-zeros-in-number

Way 2: Delete the leading zeros in Excel by VBA

Step 1: After launching the Excel, you should just press the Alt+F11 to bring up the Microsoft Visual Basic for Applications window.

open-VBA

Step 2: Select the target worksheet and click Insert>>Module.

select-the-workingsheet-and-module

Step 3: Type the under words in the coming module section and then click Run button.

Sub DeleteZero()
'updateby20140616
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "Deleteleadingzero"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
WorkRng.NumberFormat = "General"
WorkRng.Value = WorkRng.Value
End Sub
type-words-into-module-section
Step 4: Then a new dialog labelled with Deleteleadingzero would pop up and you can select the range of cells you want to delete the leading zeros with. Last, click OK. Then you would fine that the leading zeros have been deleted in the corresponding cells.
select-a-range-for-deleting-leading-zeros

Author: usefulware

A dummy who is crazy about computer. Hope to help his friends solve computer issues.

Leave a comment