[英]Write formula with Excel VBA
I have in table 1 three values.我在表 1 中有三个值。 In column
A
and C
.在
A
列和C
列中。 In B
I have a formula like this:在
B
我有一个这样的公式:
=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=""
.这意味着如果
C10
的值大于或等于1
,则A10 + C10
应写入B10
列,否则B10=""
。
I need the formular from row 10 till Row end.我需要从第 10 行到行结束的公式。
So it is better to bring this formula to Excel VBA but I have no idea how can I implement this in VBA.所以最好将此公式带到 Excel VBA,但我不知道如何在 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.请注意,
.Formula
需要标准美国英语中的公式,使用,
作为分隔符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.