我剛開始學習VBA三週前,所以隨時批評我的代碼。VBA - IIF聲明與CDate(變體)
我想用IIF
語句做什麼。如果語句中:
Dim rng_ModPlanStart as range
Dim QueryDate as Variant
Set rng_ModPlanStart = ThisWorkbook.ActiveSheet.Range("AH2:AH" & LastCell)
rng_ModPlanStart(1).Offset(-1, 0).Value = "Module Planned Start"
For Each cl In rng_ModPlanStart
QueryDate = Application.VLookup(ActiveSheet.Range("E" & cl.Row), Sheets("Chamber Schedule").Range("B:U"), 20, False)
If Not ((IsError(QueryDate))) Then
cl.Value = DateDiff("d", CDate(QueryDate), Date)
End If
Next cl
但我在嘗試使用IIF像
IIF(IsError(QueryDate), "", DateDiff("d", CDate(QueryDate), Date))
因爲VBA認爲QueryDate時出錯不是日期......它應該由CDate功能正確嗎?我錯過了什麼?
變體可以是一切。你有沒有檢查過它的內容? – RuDevel