不保留公式,主要解决以文本形式的数字转化为数字
Sub ConvertTextToNumberAllSheets()
Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
' 遍历所有工作表
For Each ws In ThisWorkbook.Worksheets
' 检查是否有足够的行和列在 A1:I8 范围内
If ws.Rows.Count >= 8 And ws.Columns.Count >= 9 Then
' 设置要转换的范围为 A1:I8
Set rng = ws.Range("A1:I8")
' 禁用警告消息
Application.DisplayAlerts = False
' 将选定范围中的所有单元格转换为数字格式
rng.NumberFormat = "0"
rng.Value = rng.Value
' 恢复警告消息
Application.DisplayAlerts = True
End If
Next ws
End Sub