跳到主要内容

如何在Excel中保留或删除前导零?

通常,当我们在单元格中键入包含前导零的数字(如00032423)时,它可能显示为32423。如何在Excel中保留这些前导零? 反之,当不需要显示前导零时,该如何删除呢?

使用格式单元格保持前导零

使用VBA删除前导零

通过点击使用 Kutools for Excel 删除前导零 好主意3

使用 Kutools for Excel 添加/删除相同的前导零


箭头蓝色右气泡 使用格式单元格保持前导零

如果要在Excel中保留前导零,则只需在键入数据之前将单元格格式设置为“文本格式”。

1.选择要输入带前导零的数据的范围单元格,然后单击右键选择 单元格格式 从上下文菜单中。 看截图:

doc-keep-delete-leader-zeor-1

2.在 单元格格式 对话框中,单击 联系电话 选项卡,然后选择 文本 来自 产品分类 窗格。 请点击 OK 关闭对话框。 看截图:

doc-keep-delete-leader-zeor-2

现在,当您在范围单元格中键入带有前导零的数字时,前导零将保留在单元格中。 看截图:

doc-keep-delete-leader-zeor-3

备注:如果您在键入数字后将单元格设置为文本格式,则此方法无效。


一键式删除Excel中单元格中的所有前导零

只需单击一下,选中的所有前导零都已删除。  点击免费试用30天!
文档删除前导零
 
Kutools for Excel:拥有300多个便捷的Excel加载项,可以在30天内免费试用。

箭头蓝色右气泡 使用VBA删除前导零

如果要删除Excel中的前导零,则有四种解决方法。

方法1:将单元格格式化为数字格式

选择要键入数字而不显示前导零的范围,然后右键单击以单击 单元格格式 打开 单元格格式 对话框,然后选择 联系电话 来自 产品分类 窗格,然后单击 OK. 

备注:如果在键入数字后格式化单元格,则此方法将不起作用。

方法2:使用公式

选择您已键入带前导零的数字的范围单元格旁边的空白单元格,然后键入此公式 = VALUE(A1) (A1表示单元格包含前导零的数字)。 然后按 输入 按钮,现在公式单元格中显示不带前导零的数字。 看截图:

doc-keep-delete-leader-zeor-4

方法3:运行VBA

1。 按 Alt + F11键 显示 Microsoft Visual Basic应用程序 窗口。

2.在窗口中,单击 插页 > 模块 以显示新的模块窗口,然后将以下VBA代码复制到模块窗口中。

VBA:在Excel中删除前导零

Sub DeleteZero()
'updateby20140616
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
WorkRng.NumberFormat = "General"
WorkRng.Value = WorkRng.Value
End Sub
3。 点击 运行 按钮,会弹出一个KutoolsforExcel对话框,供您选择一个范围以删除前导零。 看截图:

doc-keep-delete-leader-zeor-5

4。 点击 OK。 然后删除选择中的前导零。

方法4:使用转换为数字功能

选择由以零开头的数字填充的范围单元格,单击所选内容旁边的警告图标,然后选择 转换成数字 从上下文菜单中。 查看屏幕截图:

doc-keep-delete-leader-zeor-6


箭头蓝色右气泡 通过点击使用 Kutools for Excel 删除前导零

Kutools for Excel, 与超过 200 方便的功能,使您的工作更加轻松。 

安装后 Kutools for Excel,请执行以下操作:(立即免费下载Kutools for Excel!)

如果你有 Kutools for Excel,您可以通过单击两次快速删除文本中的所有前导零 删除前导零 效用

选择要删除前导零的文本,然后单击“确定”。 库工具 > 文本 > 删除前导零。 看截图:
doc删除前导零01

然后会弹出一个对话框,提醒您从多少个单元格中删除了前导零。 看截图:
doc删除前导零02

点击 OK 关闭对话框。

箭头蓝色右气泡 删除前导零




箭头蓝色右气泡 使用 Kutools for Excel 添加/删除前导零

如果要向单元格添加或删除相同数量的前导零,则可以应用 Kutools for Excel's 添加文本按位置删除 实用程序,一种可以帮助您向单元格中添加相同数量的前导零,一种可以帮助您从单元格左侧删除相同数量的字符串。

安装后 Kutools for Excel,请执行以下操作:(立即免费下载Kutools for Excel!)

添加相同数量的前导零

1.首先,您需要将单元格格式设置为 文本 通过选择它们并单击 主页 和去 数字 分组选择 文本 从下拉列表中。 看截图:
文档库工具 1

2.然后保持选中这些单元格,然后单击 库工具 > 文本 > 添加文本。 看截图:
文档库工具 2

3.在 添加文本 对话框中,在您的文本框中输入要添加的零 文本,并检查 在第一个字符之前 选项,然后您可以在右侧窗格中预览添加结果。 看截图:
文档库工具 3

4。 点击 Ok or 使用,现在将相同数量的前导零添加到单元格中。
文档库工具 4

删除相同数量的前导零

1.选择要删除前导零的单元格,然后单击 库工具 > 文本 > 按位置删除。 看截图:
文档库工具 5

2.在弹出的对话框中,输入要删除的零的数量,选中该选项,然后可以在“预览”窗格中预览结果。
文档库工具 6

3。 点击 Ok or 使用,现在前导零立即被删除。


分页浏览和编辑多个Excel工作簿/ Word文档,例如Firefox,Chrome,Internet Explore 10!

您可能熟悉在 Firefox/Chrome/IE 中查看多个网页,并通过单击相应的选项卡轻松在它们之间切换。在这里,Office Tab 支持类似的处理,允许您在一个 Excel 窗口或 Word 窗口中浏览多个 Excel 工作簿或 Word 文档,并通过单击选项卡轻松在它们之间切换。 免费点击 30Office Tab 试用一天!

优秀

相关文章:

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (21)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I want to keep the leading zero's when I copy from the program I use at work & paste onto excel with out having to manually re-enter them. I would also like to keep them when I use my scanner into excel. Using the 'Text' format I can manually re-enter them into the cell & they will stay. Is there a format so that they go in with the leading zero's already there?
This comment was minimized by the moderator on the site
Hi, McJoe, I do not understand your question clearly, if you want to copy text string with leading zeros from a program, maybe Word document, and paste them to a worksheet and keep the leading zeros, you just format the cells as text before you pasting.
This comment was minimized by the moderator on the site
I want to remove the zero infront of the - 3TT-0233449.How do I go about it?
This comment was minimized by the moderator on the site
This comment was minimized by the moderator on the site
Thanks it worked
This comment was minimized by the moderator on the site
This is the BEST Excel site for years going! IDK how they do so much volume. WorkRng.Value = WorkRng.Value =VALUE(A1) brilliant code.
This comment was minimized by the moderator on the site
value(a1) worked great, thank you soo much !
This comment was minimized by the moderator on the site
BRILLIANT WORK!!! Excellent
This comment was minimized by the moderator on the site
I wanted to display "0001" instead of "1" in excel as Excel removes leading zeroes. Solution: Use Format Cells/ Custom format/ Type = "0000" Done. Instead this page refers to "Kutools" THIRTEEN times. Who's writing this page? Obviously the author of Kutools or someone getting a kickback from it!
This comment was minimized by the moderator on the site
If you needed to use your newly formatted number to conduct an HVLookup it will not match other data that may have embedded leading zero's. The formatting method you are referring to displays the number the way you want to see it but it will not be useful in a data match or lookup while the VBA will work.
This comment was minimized by the moderator on the site
This comment is very helpful and is the correct approach for must users looking to perform this function retroactively on their data.


The Shill is also very real, lol.
This comment was minimized by the moderator on the site
You can also do

format cell > text format ( instead of Number or accounting or Currency or general )
This comment was minimized by the moderator on the site
But how to keep the leading zeroes when I download data directly from my website or from my warehouse program? The download is directly in excel, so I can not modify anything in advance. Is there any option in excel which determines in advance that the entire column or sheet must be read (downloaded) as text?
This comment was minimized by the moderator on the site
download file in.txt and open excel and desired column select and go to format cell and select as text, after this please open your .txt file and copy from .txt file and paste it in xl.... Done
This comment was minimized by the moderator on the site
Is there any way to do it from Excel tools ? In case we have n number of records this method is of no use.
This comment was minimized by the moderator on the site
using value(a1) worked great for deleting leading zeros
This comment was minimized by the moderator on the site
Nice try slick, your methods don't work. Didn't try VBA, surely there's an easier way than that.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations