我可能会对此有些不知所措,但是我选择的是单元格“ E2”,一直到最后一个单元格。
我还找到包含单词“小计”的单元格的位置,并返回地址。我希望该单元格旁边的单元格包含一个公式,该公式仅当“ F”列中的相应单元格中键入了单词“是”时,才将所有单元格从“ E2”向下累加到第一个空单元格
它可以一直运行到实际公式,但是我不确定是否遗漏了语法错误或某种错误。
Sheets(TextBox1.Value).Select
Dim LastClass As Variant
Range("E2").Select
Selection.End(xlDown).Select
LastClass = Cells(Selection.Row,
Selection.Column).Address(0, 0)
' Finds "subtotal"
Set Subtotal = Sheets(TextBox1.Value).Range("D:D")
Set Subtotal2 = Subtotal.Find("Subtotal")
SubAddress = Cells(Subtotal2.Row, Subtotal2.Column).Address(0, 0)
RR = Range(Subtotal2.Address).Row - 2
Dim RRs As String
RRs = CStr(RR)
SubAddress.Offset(1, 0).Formula = "=SUMIF(F2:F" & RRs & ",""Yes"",E2:" & LastClass & ")"
答案 0 :(得分:0)
除了让它尝试将公式放到一行而不是一列(这没什么大不了)之外,我还尝试从一个单元格String而不是该字符串表示的范围偏移。我要做的就是将SubAddress
放在Range
Sheets(TextBox1.Value).Select
Dim LastClass As Variant
Range("E2").Select
Selection.End(xlDown).Select
LastClass = Cells(Selection.Row, Selection.Column).Address(0, 0)
' Finds "subtotal"
Set Subtotal = Sheets(TextBox1.Value).Range("D:D")
Set Subtotal2 = Subtotal.Find("Subtotal")
SubAddress = Cells(Subtotal2.Row, Subtotal2.Column).Address(0, 0)
RR = Range(Subtotal2.Address).Row - 2
Dim RRs As String
RRs = CStr(RR)
Range(SubAddress).Offset(0, 1).Formula = "=SUMIF(F2:F" & RRs & ",""Yes"",E2:" & LastClass & ")"