简体   繁体   中英

Use VBA to insert a formula in a cell

I have a function that should fill 8 rows with a formula

Sub df_opbouwen()

  num_weeks = 8 + 10

  For i = 10 To num_weeks

     Sheets("Blad1").Cells(i, 2).Formula = "=WEEKNUMMER(D10)"

  Next i

End Sub

However, when I open the Excel, I still get a #name? error. That's strange because when I just enter =WEEKNUMMER(D10) in the cell it does work.

Any thoughts on what goes wrong here?

you have a small type error:

Sub df_opbouwen()

num_weeks = 8 + 10

For i = 10 To num_weeks
    Sheets("Blad1").Cells(i, 2).Formula = "=WEEKNUM(D10)"
Next i

End Sub

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