I just started learning VBA three weeks ago, so feel free to criticize my code.
I would like to use the IIF statement to execute what is inside the If statement:
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
But I get an error when trying to use IIF, for example
IIF(IsError(QueryDate), "", DateDiff("d", CDate(QueryDate), Date))
because VBA thinks QueryDate is not a date ... what should it be with the CDate function? What am I missing?
source share