vba 使用宏将数字格式转换为 Excel 中的文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20892688/
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
use macro to convert number format to text in Excel
提问by user3155186
I'ved created a macro in Excel that I use to convert column number format to Text so the number format does not change after copy/past from a text file:
我在 Excel 中创建了一个宏,用于将列号格式转换为文本,因此从文本文件复制/过去后,数字格式不会更改:
Sub ConvertBitColumn()
' ConvertBitColumn Macro
' This macro converts 3rd column of the worksheet to Text.
Dim sht As Worksheet
Set sht = ActiveSheet
sht.Columns(2).NumberFormat = "@"
End Sub
The code works fine, but the column in questin shows some green at the left hand corner for some cells, is there a way to get rid of it, or it is normal? Thanks for responding.
代码工作正常,但questin中的列在某些单元格的左角显示一些绿色,有没有办法摆脱它,或者这是正常的?感谢您的回复。
Amy
艾米
回答by brandonjsmith
The green triangle indicates that the cell has a number that's stored as text. Excel is warning you that you can't do math formulas on numbers that are formatted as text cells. Since it sounds like you actually want numbers as text based on your macro, you can turn off error checking in Excel to get rid of those pesky green triangles:
绿色三角形表示单元格有一个以文本形式存储的数字。Excel 警告您不能对格式为文本单元格的数字执行数学公式。由于听起来您实际上希望数字作为基于宏的文本,您可以关闭 Excel 中的错误检查以摆脱那些讨厌的绿色三角形:
- Click the File tab.
- Under Help, click Options.
- In the Excel Options dialog box, click the Formulas category.
- Under Error checking rules, clear the Numbers formatted as text or preceded by an apostrophe check box.
- Click OK.
- 单击文件选项卡。
- 在帮助下,单击选项。
- 在 Excel 选项对话框中,单击公式类别。
- 在错误检查规则下,清除格式为文本或前面有撇号的数字复选框。
- 单击确定。