VBA将文本转换为除公式和非数字文本之外的数字 [英] VBA to convert texts to numbers except formula and non-numeric texts
本文介绍了VBA将文本转换为除公式和非数字文本之外的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个范围(B6:T10000)
范围内的数据是空格
,#的
,数字(格式为文本)
,文本
,最重要的是公式
。
Data in the range are a mixture of blanks
,#'s
,numbers (formatted as texts)
, texts
and most importantly formulas
.
可以有人请帮助一个VBA宏来:
Can someone please help with a VBA macro to:
- 找到任何看起来像号码的东西,并将其转换为号码
- 忽略其他
- 不要将公式转换为值
很多
推荐答案
尝试一下:
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
这篇关于VBA将文本转换为除公式和非数字文本之外的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文