MACRO VBA Formula's

时间:2017-09-21 18:22:36

标签: vba excel-vba excel

你好我有以下公式来计算列数和的总和。只是总和的公式已经完美地工作了,但是如果IF公式除以得到百分比而最后一个只是简单的减法,我输入最后3个不是和的公式时遇到了麻烦。

With wks2
    With .Cells(LastRow + 1, 4)
        .Formula = "=SUM(D7:D" & LastRow & ")"
        .Resize(, 3).FillRight
    End With
    .Calculate
    .Parent.Activate
    With .Cells(LastRow + 1, 9)
        .Formula = "=SUM(I7:I" & LastRow & ")"
        .Resize(, 3).FillRight
    End With
    .Calculate
    .Parent.Activate
    With .Cells(LastRow + 1, 7)
        .Formula = "=IF(RC4=0,IF(RC6=0,0,IF(RC6<>0,1,RC6/RC4)),RC6/RC4)"
        .Resize(, 1).FillRight
    End With
    .Calculate
    .Parent.Activate
    With .Cells(LastRow + 1, 12)
        .Formula = "=IF(RC9=0,IF(RC11=0,0,IF(RC11<>0,1,RC11/RC9)),RC11/RC9)"
        .Resize(, 1).FillRight
    End With
    .Calculate
    .Parent.Activate
    With .Cells(LastRow + 1, 14)
        .Formula = "=RC[-2]-RC[-7]"
        .Resize(, 1).FillRight
    End With
    .Calculate
    .Parent.Activate
End With

0 个答案:

没有答案