|
这是俺改用“mmwwdd”老师的代码,将就用吧。
本帖最后由 wowo000 于 2022-3-3 14:54 编辑
楼主:试试下面的代码。Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim arr, r, ir, heji
If AutoFilterMode = True Then
arr = Sheet1.UsedRange
r = UBound(arr)
If Cells(r, 5).HasFormula = False Then
Me.Range("E" & r + 1 & ":G" & r + 1).FormulaR1C1 = "=subtotal(9,r2c:r[-1]c)"
Me.Range("A" & r + 1) = "合计:"
Me.Range("A" & r + 1 & ":D" & r + 1).Merge
For ir = 3 To UBound(arr)
Me.Range("G" & 3 & ":G" & ir).FormulaR1C1 = "=SUBTOTAL(109,R2C7,R2C5:RC[-2])-SUBTOTAL(109,R2C6:RC[-1])"
Next ir
End If
End If
If AutoFilterMode = False Then
arr = Sheet1.UsedRange
r = UBound(arr)
If Me.Cells(r, 5).HasFormula = True Then
Me.Cells(r, 1).EntireRow.Delete
For ir = 3 To UBound(arr)
Me.Range("G" & 3 & ":G" & ir).FormulaR1C1 = "=SUBTOTAL(109,R2C7,R2C5:RC[-2])-SUBTOTAL(109,R2C6:RC[-1])"
Next ir
End If
End If
End Sub
|
|