【发布时间】:2022-10-19 05:59:25
【问题描述】:
我在这个网站上看到了一些类似以下的解决方案,但它们不适用于我的情况:
Sub ConvertTextToNumber()
With Range("O:AD")
.NumberFormat = "General"
.Value = .Value
End With
End Sub
我的范围是从 O:AD 开始的,我需要为无限数量的值运行它。
【问题讨论】:
我在这个网站上看到了一些类似以下的解决方案,但它们不适用于我的情况:
Sub ConvertTextToNumber()
With Range("O:AD")
.NumberFormat = "General"
.Value = .Value
End With
End Sub
我的范围是从 O:AD 开始的,我需要为无限数量的值运行它。
【问题讨论】:
手动我通常将 1 放在空白单元格中,将其复制并 PasteSpecial - Operation Multiply。
这会将每个值乘以 1,强制将其识别为数字。
使用 VBA,它看起来像:
Sub Test()
'Add a temporary sheet.
'Place value in cell A1 and copy it.
'You could use a spare cell on the existing sheet if you want.
Dim wrkSht As Worksheet
Set wrkSht = ThisWorkbook.Worksheets.Add
wrkSht.Cells(1, 1) = 1
wrkSht.Cells(1, 1).Copy
'Use the copied number to multiply the text numbers.
'Update the range to suite.
ThisWorkbook.Worksheets("Sheet1").Range("D2:D4").PasteSpecial Operation:=xlMultiply
'Delete the temporary sheet.
Application.DisplayAlerts = False
wrkSht.Delete
Application.DisplayAlerts = True
End Sub
将Sheet1 更改为工作表的名称。
【讨论】:
从前端你可以只做 Data |文本到列。
一次只有一列(前端或宏中)。
您可以将此记录为宏,然后在 VBA 编辑器中添加循环遍历多个列。
【讨论】: