如果函数则如何编码
这是excel中的等效公式
if(Concrete_Class =“ A”,volume * cementfactor,“”)
Sub multiply()
Dim second As Range
Dim first As Range, prodt As Long
Dim third As Range
Dim sht As Worksheet
Dim LastRow As Long
LastRow = Cells(Rows.Count, "C").End(xlUp).Row
Set first = Range("volume")
Set third = Range("Cement")
Set second = Range("cementfactor")
For i = 1 To LastRow
third(i, 1) = first(i, 1) * second
Next i
Rows(LastRow).Select
Selection.Delete Shift:=xlUp
Range("A2").Select
End Sub
示例:
答案 0 :(得分:0)
尝试以下操作:
Sub multiply()
Dim second As Range
Dim first As Range, prodt As Long
Dim third As Range
Dim sht As Worksheet
Dim LastRow As Long
LastRow = Cells(Rows.Count, "C").End(xlUp).Row
Set first = Range("volume")
Set third = Range("Cement")
Set second = Range("cementfactor")
For i = 1 To LastRow
If Cells(i, 2).Value = "A" Then
third(i, 1) = first(i, 1) * second
End If
Next i
Rows(LastRow).Select
Selection.Delete Shift:=xlUp
Range("A2").Select
End Sub