VBA宏,格式化Excel表格按索引和帐户求和

时间:2016-10-14 18:05:51

标签: excel vba excel-vba macros

我有更多格式问题

我正在查看具有索引#(C列)和帐号#(E列)的交易表。我需要汇总整个索引中的所有条目,然后才能累计帐户中的所有条目。我有一些我正在玩的代码,但我无法弄清楚如何在获取索引总数后对帐户条目进行总计。

Sub TotalIndex()
'
Dim iRow As Integer, iCol As Integer
Dim oRng As Range
Dim fRow As Integer
Dim lRow As Integer

Set oRng = Range("c4")

iRow = oRng.Row
iCol = oRng.Column
fRow = iRow
Do
'
If Cells(iRow + 1, iCol) <> Cells(iRow, iCol) Then
    Cells(iRow + 1, iCol).EntireRow.Insert shift:=xlDown
    iRow = iRow + 1
    Range("j" & iRow).Font.Bold = True
    Range("j" & iRow).Value = "Total"
    Range("k" & iRow).Font.Bold = True
    lRow = iRow - 1
    Range("k" & iRow).Value = "=sum(k" & CStr(fRow) & ":k" & CStr(lRow) & ")"
    iRow = iRow + 1
    fRow = iRow
Else
    iRow = iRow + 1
End If
'
Loop While Not Cells(iRow, iCol).Text = ""
'
End Sub

Sub TotalAccount()
'
Dim iRow As Integer, iCol As Integer
Dim oRng As Range
Dim fRow As Integer
Dim lRow As Integer

Set oRng = Range("e4")

iRow = oRng.Row
iCol = oRng.Column
fRow = iRow


Dim laRow As Long
Dim laCol As Long

    laRow = Cells.Find(What:="*", _
                    After:=Range("A1"), _
                    LookAt:=xlPart, _
                    LookIn:=xlFormulas, _
                    SearchOrder:=xlByRows, _
                    SearchDirection:=xlPrevious, _
                    MatchCase:=False).Row

Do
'
    If Cells(iRow + 1, iCol) <> Cells(iRow, iCol) Then
        Cells(iRow + 1, iCol).EntireRow.Insert shift:=xlDown
        iRow = iRow + 1
        Range("j" & iRow).Font.Bold = True
        Range("j" & iRow).Value = "Total"
        Range("k" & iRow).Font.Bold = True
        lRow = iRow - 1
        Range("k" & iRow).Value = "=sum(k" & CStr(fRow) & ":k" & CStr(lRow) & ")"
        iRow = iRow + 1
        fRow = iRow
    Else
        iRow = iRow + 1
    End If

'
Loop While Not Cells(iRow, iCol).Text = ""
'
End Sub

我将代码分为两个功能。一个总数指数,然后另一个功能是&#34;尝试&#34;总计每个索引内的帐户。

Errors

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

看看本教程,它按照Trashman的建议做你想做的事。 https://www.youtube.com/watch?v=QuGIlPopVms