2017-01-12 1 views
0

다음 값을 사용하여 B14 & E21 범위의 값을 초과하지 않는지 확인하려고합니다. 이 범위 중 하나의 값을 초과하면 사용자에게 오류를 알리는 메시지 상자가 나타납니다.오류 검사 후 VBA 코드가 작동하지 않습니다.

코드를 검사 할 때 오류가 있으며 오류를 강조 표시하지 않지만 실행하려고 할 때 아무 것도 일어나지 않습니다.

Option Explicit 

Sub TooManyHolidays() 

Dim msg As String 
Dim Ans As VbMsgBoxResult 

If Sheets("Request Form").Range("B14") < 26 And Sheets("Request Form").Range("E21") < 10 Then 
    NewBookingCheck.NewBookingCheck 
ElseIf Sheets("Request Form").Range("B14") >= 26 Then 
    msg = (" You Dont Have Enough Holiday ") 
    Ans = MsgBox(msg, vbYesNo) 
    If Ans = vbNo Then 
     Sheets("Request Form").Select 
     Range("Employee3").ClearContents 
     Range("DateRequest").ClearContents 
     Application.DisplayAlerts = False 
     ThisWorkbook.Save 
     Application.DisplayAlerts = True 
     Application.Quit 
    End If 
    If Ans = vbYes Then 
     Sheets("Request Form").Select 
     Range("Employee3").ClearContents 
     Range("DateRequest").ClearContents 
     Range("Employee3") = Application.Username 
    ElseIf Sheets("Request Form").Range("E21") >= 10 Then 
     msg = (" You Cant Book More Than 10 Or More Days In One Request ") 
     Ans = MsgBox(msg, vbYesNo) 
     If Ans = vbNo Then 
      Sheets("Request Form").Select 
      Range("Employee3").ClearContents 
      Range("DateRequest").ClearContents 
      Application.DisplayAlerts = False 
      ThisWorkbook.Save 
      Application.DisplayAlerts = True 
      Application.Quit 
     End If 
     If Ans = vbYes Then 
      Sheets("Request Form").Select 
      Range("Employee3").ClearContents 
      Range("DateRequest").ClearContents 
      Range("Employee3") = Application.Username 
     End If 
    End If 

End If 

End Sub 
+1

무엇이'NewBookingCheck.NewBookingCheck'입니까? –

+0

디버깅 도움말을 찾는 질문 ("이 코드가 작동하지 않는 이유는 무엇입니까?")에는 원하는 동작, 특정 문제 또는 오류 및 질문 자체에서 재현하는 데 필요한 * 가장 짧은 코드가 포함되어야합니다. 분명한 문제 성명이없는 질문은 다른 독자에게 유용하지 않습니다. 참조 : [mcve]를 만드는 방법. –

+0

'Range ("B14")'와'Range ("E21")에 어떤 값을 입력 했습니까? –

답변

0

나는 아래 코드는 당신이 원하는 무엇을 줄 것이라고 생각 (나는 NewBookingCheck.NewBookingCheck 무엇인지에도 불구하고), 또는 당신은 무엇을하고있는 두 범위 ("B14")와 범위 ("E21"경우)가 허용 된 값 내에 있습니다.

Option Explicit 

Sub TooManyHolidays() 

Dim msg As String 
Dim Ans As VbMsgBoxResult 

With Sheets("Request Form") 

    If .Range("B14") < 26 And .Range("E21") < 10 Then 
     NewBookingCheck.NewBookingCheck '<-- don't know what this does ? 
    ElseIf .Range("B14") >= 26 Then 
     msg = (" You Dont Have Enough Holiday ") 
     Ans = MsgBox(msg, vbYesNo) 
     If Ans = vbNo Then 
      Range("Employee3").ClearContents 
      Range("DateRequest").ClearContents 
      Application.DisplayAlerts = False 
      ThisWorkbook.Save 
      Application.DisplayAlerts = True 
      Application.Quit 
     End If 
     If Ans = vbYes Then 
      Range("Employee3").ClearContents 
      Range("DateRequest").ClearContents 
      Range("Employee3") = Application.UserName 
     End If    
    ElseIf .Range("E21") >= 10 Then '<-- this should be directly below "If .Range("B14") < 26 And .Range("E21") < 10 Then" 
     msg = (" You Cant Book More Than 10 Or More Days In One Request ") 
     Ans = MsgBox(msg, vbYesNo) 
     If Ans = vbNo Then 
      Range("Employee3").ClearContents 
      Range("DateRequest").ClearContents 
      Application.DisplayAlerts = False 
      ThisWorkbook.Save 
      Application.DisplayAlerts = True 
      Application.Quit 
     End If 
     If Ans = vbYes Then 
      Range("Employee3").ClearContents 
      Range("DateRequest").ClearContents 
      Range("Employee3") = Application.UserName 
     End If 
    End If 

End With 

End Sub 
관련 문제