2015-10-06 34 views
2

下面的宏有什麼問題?我只想評估一個選項卡中的一個單元格是否大於另一個選項卡中的另一個單元格。然後MSGBOX:宏如果,然後...沒有找到錯誤

Sub Comhouse() 
    If Worksheets("(2.2) TRA worksheet").Range("AU425").Value > Worksheets("(2.0) Hotel Inventory").Range("S421").Value Then 
    MsgBox ("Please check inventory imputed in Com and House for every day as it may be exiding the total inventory available") 
    Exit Sub 
    Else 
    MsgBox ("All correct") 
    End If 
End Sub 
+1

似乎是確定,是在細胞中的值是否正確?他們是有效的數字嗎? – agold

+0

什麼錯誤引發你? – Trimax

+0

你是否正確處理了空值? – Greg

回答

0

檢查數值:

Sub Comhouse() 
    Dim v1 As Variant, v2 As Variant 
    v1 = Worksheets("(2.2) TRA worksheet").Range("AU425").Value 
    v2 = Worksheets("(2.0) Hotel Inventory").Range("S421").Value 
    If IsNumeric(v1) And IsNumeric(v2) Then 
     If v1 > v2 Then 
     MsgBox ("Please check inventory imputed in Com and House for every day as it may be exiding the total inventory available") 
     Exit Sub 
     Else 
     MsgBox ("All correct") 
     End If 
    Else 
     MsgBox "non-numeric values" 
    End If 
End Sub