I'm struggling to write a formula in Excel VBA.
This is my code:
Dim Formula as Range
Dim Number as Integer
Number = 1
Formula.formula = "=MAX(IF(LEFT(B7:B250,1)= & Number &, B7:B250))"
It gives a syntax error.
I'm struggling to write a formula in Excel VBA.
This is my code:
Dim Formula as Range
Dim Number as Integer
Number = 1
Formula.formula = "=MAX(IF(LEFT(B7:B250,1)= & Number &, B7:B250))"
It gives a syntax error.
You are missing some quotes:
"=MAX(IF(LEFT(B7:B250,1)=" & Number & ",B7:B250))"
Also, this is an array formula so use .FormulaArray
instead of .Formula
.