ChangeWorld
ChangeWorld

Reputation: 431

Write a formula in Excel VBA

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.

Upvotes: 0

Views: 132

Answers (1)

BigBen
BigBen

Reputation: 50008

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.

Upvotes: 1

Related Questions