我有很多来自其他来源的excel文件,我需要检查他们是否不小心将字母字符放在数字字段中。并非所有变量都只是数字,我不能简单地清除字母字符。
如何标记这些情况,以便我可以将其发送给发送数据的人注意。?
答案 0 :(得分:1)
您可以使用ISTEXT()来查看某个单元格是否包含文字,或者您可以在某个范围内使用条件格式,并查看它是否在“A”和“Z”之间,如果它的格式是背景颜色,那么:
答案 1 :(得分:1)
此代码将执行我认为您需要的操作。 将其添加到VBA编辑器中的普通模块并运行名为 catchmixedvals
的宏代码假设如下(但您可以更改它们以适应):
数据位于名为“数据”的工作表中
数据从单元格“A3”开始
包含“混合”数据的单元格将填充红色
数据保持不变
Sub catchmixedvals()
Dim ws1 As Worksheet
Dim stRow As Long, stCol As Long
Dim enRow As Long, enCol As Long
Dim drng As Range
Dim cl As Range
Set ws1 = Worksheets("Data")
stRow = 3
stCol = 1
With ws1
'determine data range
enRow = .Cells(.Rows.Count, stCol).End(xlUp).Row
enCol = .Cells(stRow, .Columns.Count).End(xlToLeft).Column
Set drng = Range(.Cells(stRow, stCol), .Cells(enRow, enCol))
'examine each cell in data range
For Each cl In drng
On Error Resume Next
If IsNumeric(cl) Then
'do nothing its a number
Else
'a text cell therefore check for digits
For i = 1 To Len(cl)
If Mid(cl, i, 1) >= "0" And Mid(cl, i, 1) <= "9" Then
cl.Interior.ColorIndex = 3
Exit For
End If
Next
End If
Next cl
End With
End Sub
答案 2 :(得分:0)
你能对字段执行算术运算并捕获异常以跳过/标记它