2014-10-28 11 views
0

저는 vb.script를 처음 사용하기 때문에이 답변을 찾을 수없는 서식 지정 질문 일 수 있습니다. 문제는 같은 통합 문서의 다른 시트에있는 셀의 데이터의 유효성을 검사하는 것입니다.중첩 된 경우 ... If 문을 사용하여 각 루프

워크 통해 반복하고 셀 영역을 만들며 :

Private Sub Validate(ByRef objWorkbook As Workbook) 

Dim strPattern As String: strPattern = "^\-{0,1}\d+(.\d+){0,1}$" 
Dim regEx As New VBScript_RegExp_55.RegExp 
Dim strInput As String 
Dim strOutput As String 
Dim Myrange As Range 
Dim regExCount As Object 
Set regExCount = CreateObject("vbscript.regexp") 
On Error Resume Next 

For Each objWorksheet In objWorkbook.Worksheets 
    If (UCase(objWorksheet.Name) = "Foo") Then 
     objWorksheet.Select 
     Range("Q2").Select 

    ElseIf (UCase(objWorksheet.Name) = "Bar") Or (UCase(objWorksheet.Name) = "Poo") Then 
     objWorksheet.Select 
     Set Myrange = ActiveSheet.Range("D51:AA76") 

     For Each cell In Myrange.Cells 
      If strPattern <> "" Then 
      strInput = cell.Value 
      strReplace = "" 

      With regEx 
       .Global = True 
       .MultiLine = True 
       .IgnoreCase = False 
       .Pattern = strPattern 
      End With 

      Set regExCount = regEx.Execute(strInput) 
      If regExCount.Count = 0 Then 
       strOutput = strOutput + "Illegal character at " + cell.AddressLocal + "\r\n" 
      End If 
     Next cell 
    End If 

Next 
MsgBox (strOutput) 

End Sub 

난 다음 셀에 대해서는, 루프없이 다음의 컴파일 오류

. 해당 줄을 제거하고 End F를 강조 표시하지 않고 Block If에 대해 End Sub를 강조 표시하면 오류가 발생합니다. End End End Sub 앞에 If가 있으면 For without without error라는 오류가 발생합니다.

답변

1

이 블록이 누락되어 종료하지 않습니까?

 If strPattern <> "" Then 
      strInput = cell.Value 
      strReplace = "" 
0

If strPattern <> "" Then 

End If ' regExCount.Count 
Next cell ' In Myrange.Cells 
사이에 폐쇄하지 귀하