Consulting

Results 1 to 3 of 3

Thread: Subtotal multiple blocks of data

  1. #1

    Subtotal multiple blocks of data

    Hi,
    I've been stuck on this for a little while now, and just can't seem to get my head around it.

    Basically, I have data that looks like this (changed some info due to confidentiality) - Pretend the RED values aren't there!!!.



    Basically, I want a macro that creates the RED values for me (subtotals each block separately), instead of doing it manually. I can't seem to work out a way of doing it?
    A subtotal at the VERY bottom isn't required... Just the separate blocks of data
    "RED" values aren't required either... It's just for illustration.


    A simple understanding macro would be great then I can try to learn it
    Thank you!!
    Last edited by ashleyuk1984; 12-12-2013 at 12:01 PM.

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Things are this are usually a little touchy depending on the data layout, so check it out


    Option Explicit
    Const iColToSum As Long = 5
    Sub test()
        Dim rArea As Range, rEnd As Range
    
        Set rEnd = ActiveSheet.Cells(ActiveSheet.Rows.Count, iColToSum).End(xlUp)
        Do While rEnd.Row > 1
            Set rArea = rEnd.CurrentRegion
            rEnd.Offset(1, 0).Value = Application.WorksheetFunction.Sum(rArea.Columns(iColToSum))
            rEnd.Offset(1, 0).Interior.Color = vbRed        ' marker
            Set rEnd = rEnd.End(xlUp)
            Set rEnd = rEnd.End(xlUp)
        Loop
    End Sub

    Paul
    Attached Files Attached Files

  3. #3
    Thank you very much. Works perfectly for my purpose. Rep given

Posting Permissions

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