|
楼主 |
发表于 2022-3-4 09:06
|
显示全部楼层
老师您好,我简单的修改了一下您的代码,表格样子和思路也稍微改动了一下,可以使用了。如果”合计“两个字在AD列跨列居中就更美观一点,您看可以吗,怎么修改呢?
- 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 & ":F" & r + 1).FormulaR1C1 = "=subtotal(9,r2c:r[-1]c)"
- Me.Range("A" & r + 1) = "合计:"
- Me.Range("A" & r + 1 & ":D" & r + 1).UnMerge
- For ir = 3 To UBound(arr)
- Me.Range("G" & 3 & ":G" & ir).FormulaR1C1 = "=SUBTOTAL(109,R2C5:RC[-2])-SUBTOTAL(109,R2C6:RC[-1])"
- ' 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,R2C5:RC[-2])-SUBTOTAL(109,R2C6:RC[-1])"
- ' SUBTOTAL(109,R2C7,R2C5:RC[-2])-SUBTOTAL(109,R2C6:RC[-1])
- Next ir
- End If
- End If
- End Sub
复制代码
?
|
|