变量总是返回为假

时间:2017-09-21 18:27:09

标签: excel vba excel-vba

我是VBA的新手,可能是解决这个问题的简单方法。我编写了以下代码,但无论如何,变量jan总是返回false。

Dim month1 As Integer
Dim month2 As Integer
Dim month3 As Integer
Dim month4 As Integer
Dim jan As Boolean

If Not IsEmpty(Sheet1.[K29]) Then month1 = month(Sheet1.[K29])
If Not IsEmpty(Sheet1.[K30]) Then month2 = month(Sheet1.[K30])
If Not IsEmpty(Sheet1.[K31]) Then month3 = month(Sheet1.[K31])
If Not IsEmpty(Sheet1.[K32]) Then month4 = month(Sheet1.[K32])

If month1 > 1 Or month2 > 1 Or month3 > 1 Or month4 > 1 Then jan = False

我已经单独测试了变量month1,month2等,并且一切看起来都很好,除了最后的条件。即使所有变量都是1,jan仍然是假的。

思想?

1 个答案:

答案 0 :(得分:3)

也许你可以这样试试......

If month1 > 1 Or month2 > 1 Or month3 > 1 Or month4 > 1 Then
    jan = False
Else
    jan = True
End If
相关问题