这应该很简单。下面是代码即时通讯与合作:Excel Vba:单元格中的公式值
Private Sub CommandButton23_Click()
Dim linerngs As Range
Dim lineitem As Range
Dim lastlinerow As Long
Dim TabLastRow
Dim claimstab As String
Dim officesrange As Range
Dim office As Range
officeslastrow = Sheet2.Range("A" & Rows.Count).End(xlUp).Row
lastlinerow = Sheet2.Range("D" & Rows.Count).End(xlUp).Row
Set officerng = Sheet2.Range("A6:A" & officeslastrow).SpecialCells(xlCellTypeConstants, 23)
Set linerngs = Sheet2.Range("D7:D" & lastlinerow).SpecialCells(xlCellTypeConstants, 23)
'Starts evaluating the first line item at the first home office
For Each lineitem In linerngs
'evaluates line item to identify which formula is needed to count it
If InStr(1, lineitem.Value, "IN") > 0 And InStr(1, lineitem.Value, "AOS") = 0 Then
lineitem.Offset(0, 16).Formula = "=SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R2C5&"" Claims'!B:B""),R[0]C[-19],INDIRECT(""'""&R2C5&"" Claims'!C:C""),R[0]C[-17],INDIRECT(""'""&R2C5&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-15],R[0]C[-14]),INDIRECT(""'""&R2C5&"" Claims'!G:G""),R[0]C[-9]:R[0]C[-1]))"
lineitem.Offset(0, 17).Formula = "=SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R3C5&"" Claims'!B:B""),R[0]C[-20],INDIRECT(""'""&R3C5&"" Claims'!C:C""),R[0]C[-18],INDIRECT(""'""&R3C5&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-16],R[0]C[-15]),INDIRECT(""'""&R3C5&"" Claims'!G:G""),R[0]C[-10]:R[0]C[-2]))"
End If
If InStr(1, lineitem.Value, "IN") > 0 And InStr(1, lineitem.Value, "AOS") > 0 Then
lineitem.Offset(0, 16).Formula = "=SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R2C5&"" Claims'!B:B""),R[0]C[-19],INDIRECT(""'""&R2C5&"" Claims'!C:C""),R[0]C[-17],INDIRECT(""'""&R2C5&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-15],R[0]C[-14])))-SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R2C5&"" Claims'!B:B""),R[0]C[-19],INDIRECT(""'""&R2C5&"" Claims'!C:C""),R[0]C[-17],INDIRECT(""'""&R2C5&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-15],R[0]C[-14]),INDIRECT(""'""&R2C5&"" Claims'!G:G""),R2C11:R2C20))"
lineitem.Offset(0, 17).Formula = "=SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R3C5&"" Claims'!B:B""),R[0]C[-20],INDIRECT(""'""&R3C5&"" Claims'!C:C""),R[0]C[-18],INDIRECT(""'""&R3C5&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-16],R[0]C[-15])))-SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R3C5&"" Claims'!B:B""),R[0]C[-20],INDIRECT(""'""&R3C5&"" Claims'!C:C""),R[0]C[-18],INDIRECT(""'""&R3C5&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-16],R[0]C[-15]),INDIRECT(""'""&R3C5&"" Claims'!G:G""),R2C11:R2C20))"
End If
If InStr(1, lineitem.Value, "Excess MO") > 0 And InStr(1, lineitem.Value, "AOS") = 0 Then
lineitem.Offset(0, 16).Formula = "=SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R2C5&"" Claims'!B:B""),R[0]C[-19],INDIRECT(""'""&R2C5&"" Claims'!C:C""),R[0]C[-17],INDIRECT(""'""&R2C5&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-15],R[0]C[-14]),INDIRECT(""'""&R2C5&"" Claims'!P:P""),"">""&R2C22,INDIRECT(""'""&R2C5&"" Claims'!G:G""),R[0]C[-9]:R[0]C[-1]))"
lineitem.Offset(0, 17).Formula = "=SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R3C5&"" Claims'!B:B""),R[0]C[-20],INDIRECT(""'""&R3C5&"" Claims'!C:C""),R[0]C[-18],INDIRECT(""'""&R3C5&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-16],R[0]C[-15]),INDIRECT(""'""&R3C5&"" Claims'!P:P""),"">""&R2C22,INDIRECT(""'""&R3C5&"" Claims'!G:G""),R[0]C[-10]:R[0]C[-2]))"
End If
If InStr(1, lineitem.Value, "Excess MO") > 0 And InStr(1, lineitem.Value, "AOS") > 0 Then
lineitem.Offset(0, 16).Formula = "=SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R2C5&"" Claims'!B:B""),R[0]C[-19],INDIRECT(""'""&R2C5&"" Claims'!C:C""),R[0]C[-17],INDIRECT(""'""&R2C5&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-15],R[0]C[-14]),INDIRECT(""'""&R2C5&"" Claims'!P:P""),"">""&R2C22))-SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R2C5&"" Claims'!B:B""),R[0]C[-19],INDIRECT(""'""&R2C5&"" Claims'!C:C""),R[0]C[-17],INDIRECT(""'""&R2C5&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-15],R[0]C[-14]),INDIRECT(""'""&R2C5&"" Claims'!P:P""),"">""&R2C22,INDIRECT(""'""&R2C5&"" Claims'!G:G""),R2C11:R2C20))"
lineitem.Offset(0, 17).Formula = "=SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R3C5&"" Claims'!B:B""),R[0]C[-20],INDIRECT(""'""&R3C5&"" Claims'!C:C""),R[0]C[-18],INDIRECT(""'""&R3C5&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-16],R[0]C[-15]),INDIRECT(""'""&R3C5&"" Claims'!P:P""),"">""&R2C22))-SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R3C5&"" Claims'!B:B""),R[0]C[-20],INDIRECT(""'""&R3C5&"" Claims'!C:C""),R[0]C[-18],INDIRECT(""'""&R3C5&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-16],R[0]C[-15]),INDIRECT(""'""&R3C5&"" Claims'!P:P""),"">""&R2C22,INDIRECT(""'""&R3C5&"" Claims'!G:G""),R2C11:R2C20))"
End If
If InStr(1, lineitem.Value, "Medical Only") > 0 Then
lineitem.Offset(0, 16).Formula = "=SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R2C5&"" Claims'!B:B""),R[0]C[-19],INDIRECT(""'""&R2C5&"" Claims'!C:C""),R[0]C[-17],INDIRECT(""'""&R2C5&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-15],R[0]C[-14]),INDIRECT(""'""&R2C5&"" Claims'!P:P""),""<""&R2C22))"
lineitem.Offset(0, 17).Formula = "=SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R3C5&"" Claims'!B:B""),R[0]C[-20],INDIRECT(""'""&R3C5&"" Claims'!C:C""),R[0]C[-18],INDIRECT(""'""&R3C5&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-16],R[0]C[-15]),INDIRECT(""'""&R3C5&"" Claims'!P:P""),""<""&R2C22))"
End If
If InStr(1, lineitem.Value, "Incident Only") > 0 Then
lineitem.Offset(0, 16).Formula = "=SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R2C5&"" Claims'!B:B""),R[0]C[-19],INDIRECT(""'""&R2C5&"" Claims'!C:C""),R[0]C[-17],INDIRECT(""'""&R2C5&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-15],R[0]C[-14])))"
lineitem.Offset(0, 17).Formula = "=SUMPRODUCT(COUNTIFS(INDIRECT(""'""&R3C5&"" Claims'!B:B""),R[0]C[-20],INDIRECT(""'""&R3C5&"" Claims'!C:C""),R[0]C[-18],INDIRECT(""'""&R3C5&"" Claims'!E:E""),CHOOSE({1;2},R[0]C[-16],R[0]C[-15])))"
End If
Next lineitem
'repeats the process for the next line item until it reaches the end
'Calculates Net Claims
For Each lineitem In linerngs
lineitem.Offset(0, 19).Formula = "=R[0]C[-3] - SUM(R[0]C[-2]:R[0]C[-1])"
Next lineitem
End Sub
一切正常,我只是喜欢它,如果只是公式结果显示在单元格,而不是整个公式。我知道这是可能的,我只是不记得过去我是如何做到的。任何帮助将不胜感激。
尝试 “Ctrl +'”?啊。这是〜键。 – findwindow