我必须计算2列(firstCol和lastCol)的值之间的差异,并在另一列(NextColumn)中设置这些差异。行计数一直在变化,所以在计算差异之前,我必须先计算rowCount。我试图用范围来编写一个循环,这样就可以计算出差异,但它似乎不起作用。
For i = 3 To lastRow
Range(Cells(3, NextColumn), Cells(lastRow, NextColumn)).FormulaR1C1 = "=Range(Cells(i, firstCol),Cells(i,firstCol)).Value - Range(Cells(i, lastCol),Cells(i,lastCol)).Value"
Next i任何帮助都将不胜感激!
谢谢你尼克
发布于 2017-09-27 17:23:02
vba需要在引号之外,而不需要循环:
Range(Cells(3, NextColumn), Cells(lastRow, NextColumn)).Formula = "=" & Cells(3, firstCol).Address(0, 0) & "-" & Cells(3, lastCol).Address(0, 0)不需要循环。Excel将根据需要更改相关引用。
https://stackoverflow.com/questions/46453441
复制相似问题