我有Range("B6:T10000")
该范围内的数据混合了blanks
,#'s
,numbers (formatted as texts)
,texts
,最重要的是formulas
。
有人可以帮助使用VBA宏来:
非常感谢
答案 0 :(得分:5)
您可以在没有代码的情况下执行此操作,也可以使用更快的代码避免循环
<强>手册强>
B6:T100001
F5
。然后Goto ... Special
Constants
然后Text
Paste Special Multiply
并检查Add
这会将仅包含数字的文本转换为数字,并仅保留实际文本或公式
<强>代码强>
Sub Update()
Dim rng1 As Range
On Error Resume Next
Set rng1 = Range("B6:T10000").SpecialCells(xlCellTypeConstants, 2)
On Error Resume Next
If rng1 Is Nothing Then Exit Sub
'presumes last cell in sheet is blank
Cells(Rows.Count, Columns.Count).Copy
rng1.PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd
End Sub
答案 1 :(得分:3)
这是我的版本:
Sub Test()
Dim rng as Range, cel as Range
Set rng = Thisworkbook.Sheets("Sheet1").Range("B6:T10000")
For Each cel In rng
If Not IsError(cel.Value) Then _
If Len(cel.Value) <> 0 And cel.HasFormula = False And _
IsNumeric(cel.Value) Then cel.Value = Val(cel.Value)
Next cel
End Sub
我测试了它,并且工作正常 希望这可以帮助。
答案 2 :(得分:2)
尝试一下:
Sub Converter()
Dim rBig As Range, r As Range, v As Variant
Set rBig = Range("B6:T10000")
For Each r In rBig
v = r.Value
If v <> "" And r.HasFormula = False Then
If IsNumeric(v) Then
r.Clear
r.Value = v
End If
End If
Next r
End Sub
修改#1 强>:
此版本忽略错误:
Sub Converter()
Dim rBig As Range, r As Range, v As Variant
Set rBig = Range("B6:T10000")
For Each r In rBig
v = r.Value
If Not IsError(v) Then
If v <> "" And r.HasFormula = False Then
If IsNumeric(v) Then
r.Clear
r.Value = v
End If
End If
End If
Next r
End Sub
答案 3 :(得分:0)
ActiveSheet.Range("b5:b6004,h5:h6004").Select
For Each xCell In Selection
If IsNumeric(xCell) = False Then
xCell.Value = Val(xCell.Value)
Else
End If
Next xCell