简体   繁体   中英

Write formula with Excel VBA

I have in table 1 three values. In column A and C . In B I have a formula like this:

=WENN(C10>=1;A10+C10;"") 

It means if the value in C10 is greater or equal than 1 , then A10 + C10 should write in column B10 , else B10="" .

I need the formular from row 10 till Row end.

So it is better to bring this formula to Excel VBA but I have no idea how can I implement this in VBA.

Something like the following should work

Dim ws As Worksheet  ' define your sheet
Set ws = ThisWorkbook.Worksheets("Sheet1")

Dim LastRow As Long  ' find last used row in column A
LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row

' write the formula 
ws.Range("B10", "B" & LastRow).Formula = "=IF(C:C>=1,A:A+C:C,"""")"

Note that .Formula requires the formula in standard US english using , as seperator.

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