简体   繁体   中英

write dynamic formula in cell using vba

Range(A1).Value = "=SUM(Range(B1), Range(B1).Offset(xlToRight))"

I want to write a formula in a cell by using VBA, but I want to make it dynamic.
How can I write this code?
What I've tried is written above.

try this:

Range("A1").Formula = "=SUM(" & Range("B1").Value & "," & Range("B1").Offset(0, 1).Value & ")"

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