Write properly a formula in VBA excel

五迷三道 提交于 2020-02-06 09:22:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!