【发布时间】:2018-05-24 15:08:29
【问题描述】:
我有:
Set QuanityRange = Sheets("Raw_Data").Range("F2:F" & lastDataRow)
MsgBox "This is the Data Range: " & vbNewLine & "Quanities: " & QuanityRange.Address()
这将在消息框中显示 $F$2:$F$1838。
如果我有:
Total = WorksheetFunction.Sum(QuanityRange)
MsgBox "Total is: " & Total
这会在消息框中显示 15170。
我的问题是我目前有:
Range("B2", Cells(lastMatrixRow, lastMatrixCol)).Formula = "=Sum(Raw_Data!$F$2:$F$10000)"
这行得通,它将 15170 放入从 B2 到 BO114 的每个单元格中,在这种情况下恰好是 (lastMatrixRow, lastMatrixCol) 的位置。
但是,我想做的是:
Range("B2", Cells(lastMatrixRow, lastMatrixCol)).Formula = "=Sum(QuanityRange)"
代替:
Range("B2", Cells(lastMatrixRow, lastMatrixCol)).Formula = "=Sum(Raw_Data!$F$2:$F$10000)"
但它不起作用。我该怎么做?
【问题讨论】:
-
放两张截图会很有帮助。并对
lastMatrixRow和lastMatrixCol进行硬编码以使其更易于理解。