Consulting

Results 1 to 6 of 6

Thread: Subtotal Macro Formula Help

  1. #1

    Subtotal Macro Formula Help

    Attach is a sample worksheet. It has simple subtotals on it. But I dont want the subtotal to sum every column. For the cash% column, i want it to be the subtotal of the cash column divided by the subtotal of the credit column. For the tax% subtotal, I want it to be the subtotal of the tax column divded by the subtotal of the cash column.

    Is there a macro for this? Like instead of the subtotal summing it, can it be divide?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]


    Sub AdjustTotals()
    Dim LastRow As Long
    Dim i As Long

    With ActiveSheet

    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    For i = 2 To LastRow

    If .Cells(i, "A") Like "*Total*" Then

    .Cells(i - 1, "H").Copy
    .Cells(i, "H").PasteSpecial xlPasteFormulas
    .Cells(i - 1, "J").Copy
    .Cells(i, "J").PasteSpecial xlPasteFormulas
    End If
    Next i
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Quote Originally Posted by xld
    [vba]


    Sub AdjustTotals()
    Dim LastRow As Long
    Dim i As Long

    With ActiveSheet

    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    For i = 2 To LastRow

    If .Cells(i, "A") Like "*Total*" Then

    .Cells(i - 1, "H").Copy
    .Cells(i, "H").PasteSpecial xlPasteFormulas
    .Cells(i - 1, "J").Copy
    .Cells(i, "J").PasteSpecial xlPasteFormulas
    End If
    Next i
    End With
    End Sub
    [/vba]
    Thank you but that just copies the last row before the subtotal of column h and j to the row of the subtotal but i want the subtotal of column H to be the subtotal of column E Divided by the subtotal of column F, same for tax except its column J divided by E

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    It copies your formula, which ives you exactly the result that you describe, in a formula.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Quote Originally Posted by xld
    It copies your formula, which ives you exactly the result that you describe, in a formula.
    you're right. But the sheet I have, it doesn't have the formulas. It is just values.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    If you give us misleading info, you will get erroneous results.

    [vba]

    Sub AdjustTotals()
    Dim LastRow As Long
    Dim i As Long

    With ActiveSheet

    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    For i = 2 To LastRow

    If .Cells(i, "A") Like "*Total*" Then

    .Cells(i, "H").FormulaR1C1 = "=RC[-3]/RC[-2]"
    .Cells(i, "J").FormulaR1C1 = "=RC[-1]/RC[-5]"
    End If
    Next i
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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