excel - Excel在数字中显示零而没有错误
问题描述
在 excel VBA 中,如何显示以下数字而不在单元格中生成“数字存储为文本”错误?
1.0
1.1
1.2
.
.
1.99
1.100
1.101
1.102
.
.
1.20
1.21
1.22
.
.
etc...
解决方案
只需跟踪需要显示的小数位数。例如:
Sub marine()
Dim s As String, i As Long, a
s = "1.0,1.1,1.2,1.99,1.100,1.101,1.102,1.20,1.21,1.22"
arr = Split(s, ",")
i = 1
For Each a In arr
With Cells(i, 1)
.Value = a
brr = Split(a, ".")
.NumberFormat = "0." & Application.Rept("0", Len(brr(1)))
End With
i = i + 1
Next a
End Sub
这是基于一个奇怪的事实,即如果 VBA 将类似数字的字符串放入单元格中,Excel 会将其转换为数字:
Sub demo()
Dim s As String
s = "1.230"
Range("A1").Value = s
End Sub
编辑#1:
另一方面,如果您想输入看起来像数字的文本,但要避免引发错误标志,那么:
Sub Macro1()
Application.ErrorCheckingOptions.NumberAsText = False
End Sub
推荐阅读
- c# - 在 C# 中,我很想为字符串定义 > 和 < 运算符
- python - 基于关键字状态的侦听器在机器人框架中测试状态更新
- python - 将 MDF 文件中的通道组合到嵌套结构中
- html - 您好我正在尝试使用 SVG 制作带有文本的加载屏幕。但是每次文本没有到达我想要的位置时,它就会出现在网站徽标的后面
- shapefile - 无法在 R 中加载 shapefile
- c++ - 简单的 C++ 计算器总是输出 16
- google-sheets - 是否可以在不冻结的情况下在 Google 表格中创建可滚动表格?
- ios - 使用 AVPlayer 分散视频注意力
- c# - 将 C# 片段转换为 Dart 以获得二维数组
- oracle - Oracle REST POST 请求返回 sys_refcursor 的问题