我刚刚运行了一个宏并得到了以下内容:
Sub Macro1()
'
' Macro1 Macro
'
'
Columns("B:B").Select
Range("B4").Activate
Selection.NumberFormat = "0.00"
Selection.NumberFormat = "@"
End Sub
现在无法理解 Selection.NumberFormat = "0.00"
和 Selection.NumberFormat = "@"
之间的区别,你能帮我理解吗?
我还尝试将 Excel 中的一些文本文本转换为数字。这样做的好语法是什么?
快照:
编辑
我尝试将所有存储为文本
的数字转换为下面的数字,但没有任何改变。如果我错了,请指导:
objSheet1.Columns(11).NumberFormat = "0"
最佳答案
这就是你正在尝试的吗?
Sub Sample()
Dim ws As Worksheet
Dim lRow As Long, i As Long
'~~> Change this to the relevant sheet name
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
'~~> Col B
.Columns(2).NumberFormat = "0.00"
'~~> Get the last row
lRow = .Range("B" & .Rows.Count).End(xlUp).Row
For i = 1 To lRow
.Range("B" & i).Formula = .Range("B" & i).Value
Next i
End With
End Sub
屏幕截图
关于excel - 如何将Excel中的文本数字转换为数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14100216/