返回列表 上一主題 發帖

[發問] IF AND OR 如何適用?

[發問] IF AND OR 如何適用?

若想用VBA 的IF句法,來判斷每季財報自動更新,該如何寫?
If .Cells(r, "EN") = "" Or (Date >= DateSerial(Year(Date), 3, 31) And Date < DateSerial(Year(Date), 4, 1)) Or (Date >= DateSerial(Year(Date), 5, 14) And Date < DateSerial(Year(Date), 5, 16)) Or (Date >= DateSerial(Year(Date), 8, 14) And Date < DateSerial(Year(Date), 8, 16)) Or (Date >= DateSerial(Year(Date), 11, 14) And Date < DateSerial(Year(Date), 11, 16)) Then Exit Sub
出現程式物件定義錯誤,請前輩高手指正!
Lin

回復 1# Lin-excel


    r 可能是 0 造成的
{...} 表示需要用 CTRL+SHIFT+ENTER 三鍵輸入公式

TOP

回復 1# Lin-excel

我會拆成好幾條判式,比較容易閱讀

        Y = Year(Date)
        If .Cells(r, "EN") = "" Then Exit Sub
        If Date >= DateSerial(Y, 3, 31) And Date < DateSerial(Y, 4, 1) Then Exit Sub
        If Date >= DateSerial(Y, 5, 14) And Date < DateSerial(Y, 5, 16) Then Exit Sub
        If Date >= DateSerial(Y, 8, 14) And Date < DateSerial(Y, 8, 16) Then Exit Sub
        If Date >= DateSerial(Y, 11, 14) And Date < DateSerial(Y, 11, 16) Then Exit Sub
{...} 表示需要用 CTRL+SHIFT+ENTER 三鍵輸入公式

TOP

謝謝版主賜教,感恩!
Lin

TOP

        靜思自在 : 為人處世要小心細心,但不要「小心眼」。
返回列表 上一主題