2017-02-09 118 views
0
lastRow44 = Cells(Rows.Count, "A").End(xlUp).Row 
LastRow3 = Worksheets("Temp").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Row 

Range("A" & LastRow3).End(xlDown).Offset(0, 11).Formula = "=Sum(M50:M" & lastRow44 & ")" 

我想修改vba代码以使其更加动态。我想设置和数计算更加动态。所以我正在尝试像Range("A" & LastRow3).End(xlDown).Offset(0, 11).Formula = "=Sum(("M" & LastRow3).End(xlDown).Offset(0, 11) & lastRow44 & ")" 这样的自动将起始单元定义为M50。然而,它不是我想要的。有什么办法可以修改代码来计算开始单元格的动态值吗?使用vba填充公式使用vba设置启动单元格动态

谢谢!

+0

您用于定义.formula的公式需要更好的报价管理。=“= sum(M”&lastrow3&“:X”&lastrow44&“)”这将是第一大步。 – Cyril

+0

X假定你想要的偏移量+11从M(第13个字母)到X(第24个字母)。 – Cyril

回答

0

如何类似的东西:

lastRow44 = Cells(Rows.Count, "A").End(xlUp).Row 
For x = 50 To LastRow3 
Range("A" & x).Formula = "=Sum(""M""" & x & "": M "" & lastRow44 & ")" 
Next x 
1

尝试改变

lastRow44 = Cells(Rows.Count, "A").End(xlUp).Row 
LastRow3 = Worksheets("Temp").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Row 

lastRow44 = Sheets("Temp").Cells(Rows.Count, 1).End(xlUp).Row 
LastRow3 = Worksheets("Temp").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row 

而且,我不知道你想与实现什么

Range("A" & LastRow3).End(xlDown).Offset(0, 11).Formula = _ 
"=Sum(("M" & LastRow3).End(xlDown).Offset(0, 11) & lastRow44 & ")" 

你的公式正在做的是首先设置到你定义的拉斯特罗,然后向下搜索(就像你按CTRL +向下箭头)。如果这不符合您的要求,请尝试删除两者中的“.END(xlDown”部分。

最后,如果您知道您使用的偏移量为11,为什么不将它设置为使用“M”而不是A ,并且根本不会抵消?

相关问题