samedi 31 octobre 2020

How do you use an IF/THEN statement to do a VLookUp statement down a range taking into account the error code?

I am trying to do a VLookUp through an IF/THEN statement.

My Excel formula would be:

    =If(F2=G2,Today(),Vlookup(A2,[Range],15,FALSE))

When that would give me an "n/a" error, I would the use the following formula:

    =IF(VALUE(LEFT(C2,1))>8,N2+28,N2+14))"

I am trying to combine these in a macro and cannot get the syntax worked out.

Here is what I am 'trying' so far:

    For RowNumber = Range("M" & Rows.Count).End(xlUp).Row To 2 Step -1
    With WS2
        If Range("F" & RowNumber).Value = Range("G" & RowNumber).Value Then Range("O" & RowNumber) = (Now) Else Range("O" & RowNumber) = MyStringVar1 = Application.WorksheetFunction.VLookup(Range("A" & RowNumber), WS4.Range("A2:V5000").Value, 15, False)"
        On Error GoTo 0
        If MyStringVar1 = "" Then Range("O" & RowNumber).Value = Range("O" & RowNumber).Value = "=IF(VALUE(LEFT(Range("C" & RowNumber).Value,1))>8,Range("N" & RowNumber).Value+28,Range("N" & RowNumber).Value+14))" Else Range("O" & RowNumber).Value = MyStringVar1
    End With
    Next RowNumber

Aucun commentaire:

Enregistrer un commentaire