2015-10-06 44 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