1

I have the following formula,

=IF(valumeasure3!E2="Buy Notional Amount",VLOOKUP(C2,valumeasure3!C:U, COLUMNS(C:U),FALSE),0)

trying to automate this formula in vba, I get a syntax error. Vlookup formulas work fine, but as soon as I do the IF statement i get syntax error. I believe it is to do with the =

Range("R2").Select
        ActiveCell = "=IF(valumeasure3!E2="Buy Notional Amount",VLOOKUP(C2,valumeasure3!C:U, COLUMNS(C:U),FALSE),0)"   ''buy currency amt
        Selection.AutoFill Destination:=Range("R2:R4182")
excelguy
  • 1,574
  • 6
  • 33
  • 67

1 Answers1

1

In VBA, when you use quotation marks you are setting a boundary to a string. You should use double quotes.

Range("R2").Select
    ActiveCell = "=IF(valumeasure3!E2=""Buy Notional Amount"",VLOOKUP(C2,valumeasure3!C:U, COLUMNS(C:U),FALSE),0)"    ''buy currency amt
    Selection.AutoFill Destination:=Range("R2:R4182")

However, a suggestion is that I would recommend that you not use .Select and ActiveCell whenever possible.

Dim Rng as Range
Set Rng = Range("R2")
Rng.Value = ....
K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43