Results 1 to 15 of 15

Filter Column by Value, if dups Aggregate Rows to 1 Rows

Threaded View

  1. #15
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Filter Column by Value, if dups Aggregate Rows to 1 Rows

    Adding the new columns at the end required that we initialize them in order to establish the array bounds - try this:

    Sub SteinIII(): Dim P, Q, r As Long, s As Long, wa As Worksheet
    Dim ID As String, n As Long, k As Long: s = 2
                    Set wa = Sheets("Daily Input")
            If ActiveSheet.Name <> wa.Name Then Exit Sub
                        wa.AutoFilterMode = False
            wa.Cells(1, 35) = "Avg": wa.Cells(1, 36) = "Agg"
              wa.Columns("AI:AJ").NumberFormat = "0.00"
        P = wa.Cells(1, 2).CurrentRegion: wa.UsedRange.Offset(1).ClearContents
        Q = wa.Cells(1, 1).Resize(UBound(P, 1), UBound(P, 2))
            With CreateObject("Scripting.Dictionary")
                For r = 2 To UBound(P, 1): ID = P(r, 34): P(r, 36) = P(r, 11) * P(r, 8)
                If ID <> "" Then
            If .Exists(ID) Then
            k = .Item(ID): Q(k, 36) = Q(k, 36) + P(r, 36): Q(k, 11) = Q(k, 11) + P(r, 11)
            Else: .Item(ID) = s
            For n = 1 To UBound(P, 2): Q(s, n) = P(r, n): Next n: s = s + 1
            End If
            Else
            For n = 1 To UBound(P, 2): Q(s, n) = P(r, n): Next n: s = s + 1
            End If: Next r: k = s
            For r = 2 To s - 1: Q(r, 35) = Q(r, 36) / Q(r, 11): Next r
            wa.Cells(1, 1).Resize(UBound(Q, 1), UBound(Q, 2)) = Q
            End With
    End Sub
    Last edited by xladept; 01-29-2019 at 12:49 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Aggregate Rows of Data if Condition is met (if 2 Columns contains dup values)
    By popcorn7 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 09-28-2018, 10:27 AM
  2. [SOLVED] Loop to scan data and aggregate Rows that are the same
    By lougs7 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-18-2018, 06:48 PM
  3. [SOLVED] Aggregate results from multiple rows
    By Kyba in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-26-2017, 08:52 AM
  4. Aggregate function to number rows
    By cdumper in forum Excel General
    Replies: 9
    Last Post: 09-27-2014, 07:22 PM
  5. [SOLVED] Insert Blank Rows between existing data based on dups in sheet2
    By Melissa Camp in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-29-2014, 07:07 AM
  6. [SOLVED] Need multiple duplicate rows summed into one row for each product/version, delete dups
    By gereckes in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-03-2014, 04:33 PM
  7. [SOLVED] multiple rows with some dups where I need result on one line
    By VAN GOGH in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-26-2006, 06:50 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1