【发布时间】:2020-01-13 09:46:33
【问题描述】:
我回到了这个我不完全理解的公式(但比上次更好;)How to add a Dollar $ sign to a complex formula?)并编辑它以在其他地方使用它......
我的问题很简单,我采用完全相同的公式,但根据我在“with”中的写法,它不会给出相同的结果:(
我的目标是制作一个漂亮的大“with”,在单元格中插入公式,同时格式化单元格(颜色等)
我有这两种写法:
第一个给了我想要的结果:=AVERAGE('C Labour Rate'!c6:g6)
第二个给出:=AVERAGE('C Labour Rate'!E9:I9)
With Worksheets(YearToFill)
.Cells(PosStartLine + (TPINb * 3) - 3, PosStartColumn + (ActiveColumn - 1)).Formula = "=AVERAGE('" & LabourSheet & "'!" & .Cells(PosStartLine + (TPINb * 3) - 1, PosStartColumn + (ActiveColumn - 1) * NbRepairCodes) _
.Address(False, False) & ":" & .Cells(PosStartLine + (TPINb * 3) - 1, PosStartColumn + (ActiveColumn - 1) * NbRepairCodes + NbRepairCodes - 1).Address(False, False) & ")"
End With
(这个给=AVERAGE('C Labour Rate'!C6:G6))
With Worksheets(YearToFill).Cells(PosStartLine + (TPINb * 3) - 3, PosStartColumn + (ActiveColumn - 1)) 'Formula for the average occurences of the TPI in Europe
.Formula = "=AVERAGE('" & LabourSheet & "'!" & .Cells(PosStartLine + (TPINb * 3) - 1, PosStartColumn + (ActiveColumn - 1) * NbRepairCodes) _
.Address(False, False) & ":" & .Cells(PosStartLine + (TPINb * 3) - 1, PosStartColumn + (ActiveColumn - 1) * NbRepairCodes + NbRepairCodes - 1).Address(False, False) & ")"
End With
(第二个给=AVERAGE('C Labour Rate'!E9:I9))
那里发生了什么? 我什至尝试了一个接一个地写下两个公式,并通过逐步模式运行代码来检查结果,它显然没有相同的结果......
我猜是“.cells”造成了问题,但为什么呢?根据活动单元格没有“偏移”或其他功能...
我不明白,也没有在网上找到帮助,主要是因为我不知道如何搜索:'(
提前感谢您的帮助! :)
【问题讨论】:
标签: excel vba formula with-statement