0

我写了一个公式(IF 语句),它是完全可用的:

Formula = "=IF(R3C5=""Feb"",Actuals!R133C35,IF(R3C5=""Mar"",SUM(Actuals!R133C35:R133C36),IF(R3C5=""Apr"",SUM(Actuals!R133C35:R133C37),IF(R3C5=""May"",SUM(Actuals!R133C35:R133C38),IF(R3C5=""Jun"",SUM(Actuals!R133C35:R133C39),IF(R3C5=""Jul"",SUM(Actuals!R133C35:R133C40),IF(R3C5=""Aug"",SUM(Actuals!R133C35:R133C41),IF(R3C5=""sep"",SUM(Actuals!R133C35:R133C42),IF(R3C5=""Oct"",SUM(Actuals!R133C35:R133C43),IF(R3C5=""Nov"",SUM(Actuals!R133C35:R133C44),IF(R3C5=""Dec"",SUM(Actuals!R133C35:R133C45),"""")))))))))))*1000"

问题是,我已经硬编码了 IF 函数的行。我引用的初始单元格(R3C5)不需要更改。但是,每当我引用第 133 行时,我都需要它是动态的,因为该行可能每个月都会发生变化。我需要它来引用工作表中最后使用的行。列不需要是动态的,只要是行。我该怎么办?

4

1 回答 1

0

回答:

Dim LR As Long
Dim sLongFormula$
 Set sourceSheet = Worksheets("Actuals")
        With sourceSheet
        LR = .Cells(.Rows.Count, "I").End(xlUp).Row
        sLongFormula = "=IF(Pivot!R3C5=""Feb"",Actuals!R" & LR & "C35,IF(Pivot!R3C5=""Mar"",SUM(Actuals!R" & LR & "C35:R" & LR & "C36),IF(Pivot!R3C5=""Apr"",SUM(Actuals!R" & LR & "C35:R" & LR & "C37),IF(Pivot!R3C5=""May"",SUM(Actuals!R" & LR & "C35:R" & LR & "C38),IF(Pivot!R3C5=""Jun"",SUM(Actuals!R" & LR & "C35:R" & LR & "C39),IF(Pivot!R3C5=""Jul"",SUM(Actuals!R" & LR & "C35:R" & LR & "C40),IF(Pivot!R3C5=""Aug"",SUM(Actuals!R" & LR & "C35:R" & LR & "C41),IF(Pivot!R3C5=""Sep"",SUM(Actuals!R" & LR & "C35:R" & LR & "C42),IF(Pivot!R3C5=""Oct"",SUM(Actuals!R" & LR & "C35:R" & LR & "C43),IF(Pivot!R3C5=""Nov"",SUM(Actuals!R" & LR & "C35:R" & LR & "C44),IF(Pivot!R3C5=""Dec"",SUM(Actuals!R" & LR & "C35:R" & LR & "C45),"""")))))))))))*1000"
        End With
于 2017-08-10T15:34:34.603 回答