Results 1 to 2 of 2
  1. #1
    Star Lounger
    Join Date
    Nov 2003
    Location
    Tampa, Florida, USA
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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[attachment=83633:Book2.xls]
    [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]
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •