1

I would like to insert a function looking like this, using VBA:

=IF(ISERROR(VLOOKUP(B12,AASD!A:B,2,0)),"Check #",VLOOKUP(B12,AASD!A:B,2,0))

Code from VBA:

Sheets("Sheet1").Range("C12").Formula = "=IF(ISERROR(VLOOKUP(B12,AASD!A:B,2,0)),"Check AA#",VLOOKUP(B12,AASD!A:B,2,0))"

Issue is the "" quotes for inserting the string in the IF formula messes up the "" quotes in VBA.

Is there a clever work around for this?

Oday Salim
  • 1,129
  • 3
  • 23
  • 46

2 Answers2

4

Just double them up

Sheets("Sheet1").Range("C12").Formula = "=IF(ISERROR(VLOOKUP(B12,AASD!A:B,2,0)),""Check AA#"",VLOOKUP(B12,AASD!A:B,2,0))"

You can also use Chr(34) in place of a single set of quotes.

SJR
  • 22,986
  • 6
  • 18
  • 26
3

Additionally, that formula can be cut in half with IFERROR.

Sheets("Sheet1").Range("C12").Formula = _
   "=IFERROR(VLOOKUP(B12, AASD!A:B, 2, 0), ""Check AA#"")"