Consulting

Results 1 to 6 of 6

Thread: Sum amounts based on another column

  1. #1
    VBAX Regular
    Joined
    Sep 2011
    Posts
    42
    Location

    Sum amounts based on another column

    Hi there,

    Sorry to bother everyone, but I am trying to sum the amounts in col L, based on each change in col C. (i.e for every change in PO #, I would like the amounts summed and placed in the column next to it). I am trying to produce the highlighted values in yellow in column M without having to do it manually.

    I know the subtotal function produces the totals, however it is located in the same column as the amounts making it hard to read and I have to use the subgroup feature to see the changes, but sometimes need to see all of the data

    Can someone help if it's not too hard to write a macro?

    Thank you
    Attached Files Attached Files

  2. #2
    VBAX Mentor Teeroy's Avatar
    Joined
    Apr 2012
    Location
    Sydney, Australia
    Posts
    414
    Location
    Hi Jaydee,

    Try:

    [vba]Sub instant_sum()
    Dim rStart As Range, rCurrent As Range
    Dim lastrow As Long
    With Sheets("Recon 1501")
    Set rStart = .Range("C4")
    lastrow = .Range("C" & Rows.Count).End(xlUp).Row
    Set rCurrent = rStart
    Do
    If rCurrent.Offset(1, 0).Value <> rCurrent.Value Then
    Range("M" & rCurrent.Row).Formula = "=Sum(L" & rStart.Row & ":L" & rCurrent.Row & ")"
    Set rStart = rCurrent.Offset(1, 0)
    End If

    Set rCurrent = rCurrent.Offset(1, 0)
    Loop While rCurrent.Row <= lastrow
    End With
    End Sub
    [/vba]
    _________________________________________________________________________
    "In theory there is no difference between theory and practice. In practice there is." - Chuck Reid

    Any day you learn something new is a day not wasted.

  3. #3
    VBAX Regular
    Joined
    Sep 2011
    Posts
    42
    Location
    Thanks Teeroy, works great! I appreciate your help

  4. #4
    VBAX Regular
    Joined
    Feb 2009
    Posts
    9
    Location
    Formula option in M4:
    =IF(C4=C5,"",SUMIF(C$4:C$68,C4,L$4:L$68))
    Fill down

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,455
    Location
    [VBA]Public Sub AddSumFormula
    Dim lastrow As Long

    With Worksheets("Recon 1501")

    lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
    .Range("M4").Resize(lastrow - 3).Formula = "=IF(C4=C5,"""",SUMIF($C:$C,$C4,$L:$L))"
    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

  6. #6
    VBAX Newbie
    Joined
    Jan 2013
    Posts
    1
    Location
    Hi,
    This example is similar to what I've been scratching my head to do.So thanks to all contributors.
    Is there a same way I can add the count in another column without having to manually insert them in for hundred of records? I'm hoping to then do add an average in another column.
    Any help much apprecitaed.
    Thanks in advance.

Posting Permissions

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