构造R1C1以在工作表函数中使用

时间:2015-01-12 07:22:04

标签: excel excel-vba vba

我用过" RowNKC"对于R1C1公式的行,但它在excel函数中

Dim RowNKC As Integer    
RowNKC = Range("CuoiNKC").Row - 1   
Dim RowCDPS As Integer   
RowCDPS = Range("CuoiCDPS").Row - 1    
Dim i As Integer    
For i = 9 To RowCDPS
    If Cells(i, 9).Formula = Space(0) Then
       Cells(i, 7).Formula = "=SUMIF(**"NKC!R9C12:R" & RowNKC & "C12"**,CDPS!RC[-6],NKC!R9C15:R1189C15)"

1 个答案:

答案 0 :(得分:1)

在R1C1语法中分配公式时,您需要使用.FormulaR1C1。 (可选)只检查列I中是否存在公式,而不是将其与零长度字符串进行比较。假设Range("CuoiNKC")Range("CuoiCDPS")是指定单个单元格的定义名称,以下各项应该可以帮助您入门。

Dim i As Long, RowNKC As Long, RowCDPS As Long
With ActiveSheet
    RowNKC = Range("CuoiNKC").Row - 1
    RowCDPS = Range("CuoiCDPS").Row - 1
    For i = 9 To RowCDPS
        If Not .Cells(i, 9).HasFormula Then
           .Cells(i, 7).FormulaR1C1 = "'=SUMIF(NKC!R9C12:R" & RowNKC & "C12 , CDPS!RC[-6], NKC!R9C15:R1189C15)"
        End If
    Next i
End With

我不认为该公式实际上会起作用,因为SUMIF function需要在 sum_range 中具有与条件范围相同的行数