• Total and Sumif based on Groups

    • This topic has 1 reply, 2 voices, and was last updated 16 years ago.
    Author
    Topic
    #459630

    I’m trying to write the VBA for totaling by group.

    What I want to do
    For each Column Sum the total and Depending upon the number of Groups Sumif the total for the group

    This is what I have so far
    [codebox]
    Sub CreateTotals()
    Dim TotalRow As Range
    TotalRow = Cells(“B5:B” & Cells(Rows.Count, 2).End(xlDown).Row + 1
    Cells(TotalRow, 2).Value = “Totals”
    Cells(TotalRow, 2).Resize(1, 7).FormulaR1C1 = “=Round(Sum(R5C:R[-1]C),2)”[/codebox]

    Viewing 0 reply threads
    Author
    Replies
    • #1159754

      I’d enter the values 1, .., 4 in B24:B27, and format them as “Group “0” Total”.
      You can then use code like this:

      Code:
      Sub CreateFormulas()
        With Range("C24:I27")
      	.FormulaR1C1 = "=SUMIF(R5C2:R22C2,RC2,R5C:R22C)"
      	.NumberFormat = "$#,##0.00"
        End With
      End Sub
    Viewing 0 reply threads
    Reply To: Reply #1159754 in Total and Sumif based on Groups

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel