我正在尝试在VBA中输入SUMIF公式,但是单元格的范围可能会根据另一个选项卡上的“ Lastrow”而变化。我可以毫无问题地获得Lastrow,但问题是尝试输入我的SUMIF公式。“ Lastrow”值应替换单元格Q156和H156。希望这是有道理的。任何建议欢迎。
见下文:
Sub UpdateReconData()
Dim Lastrow6 As Integer
'gets last Row on Formatting Spreadsheet
Sheets("Formatting").Select
Lastrow6 = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
Sheets("Recon").Select
Range("B2").Select
ActiveCell.Value = _
"=SUMIF(Formatting!$Q$2:$Q$156(Recon!$A2&Recon!B$1),Formatting!$H$2:$H$156)"
End Sub
您可以将Lastrow6
变量连接到公式字符串中。您可以通过使用&符号将字符串与变量连接起来。
Range("B2").Value = _
"=SUMIF(Formatting!$Q$2:$Q$" & Lastrow6 & _
"(Recon!$A2&Recon!B$1),Formatting!$H$2:$H$" & Lastrow6 & ")"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句