VBA识别范围内的数字

我相信这是一个简单的,但似乎没有find任何明确的WWW。

我需要我的代码来识别列中的1到9之间的任何数字,以便将该错误返回给该范围,目前我只能使用一个数字来处理它。

Public Sub ErrorCheck() Dim FindString As String Dim Rng As Range FindString = "" If VBA.Trim(FindString) <> "" Then With Sheets("Scoring").Range("S:S") Set Rng = .Find(What:=FindString, _ After:=.Cells(.Cells.Count), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) If Not Rng Is Nothing Then MsgBox "Error", True Else End If End With End If End Sub 

谢谢你的帮助!

您可以迭代执行您的代码,以获取所需的所有值。 例:

 Public Sub ErrorCheck() Dim FindString As String Dim Rng As Range Dim startVal As Integer, endVal As Integer startVal = 1 endVal = 9 For i = startVal To endVal FindString = CStr(i) With Sheets("Scoring").Range("S:S") Set Rng = .Find(What:=FindString, _ After:=.Cells(.Cells.Count), _ LookIn:=xlValues, _ LookAt:=xlWhole, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) If Not Rng Is Nothing Then MsgBox "Error", True Exit For Else End If End With Next i End Sub