+ Reply to Thread
Results 1 to 4 of 4

VB Code to find Unique Names and sum the total

Hybrid View

rizmomin VB Code to find Unique Names... 08-23-2017, 11:36 AM
AliGW Re: VB Code to find Unique... 08-23-2017, 11:45 AM
MickG Re: VB Code to find Unique... 08-23-2017, 11:49 AM
YasserKhalil Re: VB Code to find Unique... 08-23-2017, 12:13 PM
  1. #1
    Valued Forum Contributor
    Join Date
    01-18-2007
    Location
    Georgia
    MS-Off Ver
    2010
    Posts
    4,434

    VB Code to find Unique Names and sum the total

    Hello:

    Please refer to attached file.
    I need VB code to find unique names from Column A and Paste at cell G7 and add corresponding total from cell H7 down.
    Let me know if you have any questions.G
    Thanks.

    Riz
    Attached Files Attached Files

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,278

    Re: VB Code to find Unique Names and sum the total

    It can be done with a formula - does it have to be VBA?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: VB Code to find Unique Names and sum the total

    Try this:-
    Sub MG23Aug13
    Dim Rng As Range, Dn As Range, n As Long
    Set Rng = Range(Range("A7"), Range("A" & Rows.Count).End(xlUp))
    With CreateObject("scripting.dictionary")
    .CompareMode = vbTextCompare
    For Each Dn In Rng
        If Not .Exists(Dn.Value) Then
            .Add Dn.Value, Dn.Offset(, 2).Value
        Else
            .Item(Dn.Value) = .Item(Dn.Value) + Dn.Offset(, 2).Value
        End If
    Next
    Range("G7").Resize(.Count, 2) = Application.Transpose(Array(.Keys, .items))
    End With
    End Sub
    Regards Mick

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: VB Code to find Unique Names and sum the total

    Try this code
    Sub Test()
        Dim dic     As Object
        Dim v       As Variant
        Dim s       As Variant
        Dim i       As Long
    
        Set dic = CreateObject("scripting.dictionary")
    
        v = Range("A7:C" & Cells(Rows.Count, 1).End(xlUp).Row).Value
        For i = 1 To UBound(v)
            s = v(i, 1)
            If Not dic.exists(s) Then dic(s) = Array(, 0)
            dic(s) = Array(v(i, 1), dic(s)(1) + v(i, 3))
        Next i
    
        With Range("G7")
            .Resize(dic.Count, 2).Value = Application.Transpose(Application.Transpose(dic.items))
        End With
    End Sub
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] VB Code to find Unique names and consolidate
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-19-2016, 06:05 PM
  2. [SOLVED] VB Code to find unique names
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-16-2016, 05:37 PM
  3. Code to find Unique Names
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-19-2016, 04:29 PM
  4. VB Code to find Unique Names
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-30-2015, 06:42 PM
  5. vba find unique names in multiple columns
    By Konexcelmath in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-26-2014, 09:10 PM
  6. Find unique names in certain range.
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 07-22-2014, 04:00 PM
  7. Replies: 3
    Last Post: 07-04-2012, 11:15 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