1

我确信这是一个简单的,但似乎无法在 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

谢谢你的帮助!

4

1 回答 1

1

您可以针对所需的所有值迭代地执行代码。例子:

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
于 2013-07-04T14:28:07.537 回答