vba 将单元格值格式化为电话号码格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10435355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 16:01:03  来源:igfitidea点击:

format cell values to phone number format

excel-vbavbaexcel

提问by user793468

I have phone numbers listed in Column A of Sheet1. Currently they dont have any format and are stored as: 1112223333

我在 Sheet1 的 A 列中列出了电话号码。目前它们没有任何格式并存储为:1112223333

I want to convert them to: 111.222.3333

我想将它们转换为:111.222.3333

I tried:

我试过:

Format(Worksheets("Sheet1").Range("A1").Value, "###.###.####")

which gives me "1112223333.."

这给了我“1112223333..”

EDIT: When I try to format it to:

编辑:当我尝试将其格式化为:

Format(Worksheets("Sheet1").Range("A1").Value, "(###) ###-####")

It works perfectly fine: (111) 222-3333

它工作得很好:(111) 222-3333

Its just with the "111.222.3333" format that I am having issues with. Am I missing something here?

它只是我遇到问题的“111.222.3333”格式。我在这里错过了什么吗?

Thanks in advance

提前致谢

回答by Doug Glancy

The periods need to be converted to text, otherwise they're read as decimal points:

句点需要转换为文本,否则它们将被读取为小数点:

Worksheets("Sheet1").Range("A1").NumberFormat = "###"".""###"".""####"