简体   繁体   中英

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM