问题
I'm struggling to write a formula in VBA excel.
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 my syntax error.
Could you help me out? Thank you.
回答1:
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
.
来源:https://stackoverflow.com/questions/59949930/write-properly-a-formula-in-vba-excel