+ Reply to Thread
Results 1 to 4 of 4

Thread: Macro to Group Data

  1. #1
    Registered User
    Join Date
    02-08-2012
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    4

    Macro to Group Data

    Excel Example.xlsxHello guys, I am relatively new to VBA (and the forum) and I was wondering if someone could offer some advice on a macro to group together cells based on information in a different column. I attached an example of what I need done. The information is on Sheet1 of the workbook, and I'd like the macro to group together document names (column D) based on their document ID (Column C). I'd like to have all the document names that correspond to one document ID in a list format in one cell next to their document ID's placed in row H. Pivot tables are out of the question as I have 1000's of rows of data, and the document names for a specific ID need to go in a list in one cell. Any ideas on what macro to use would be greatly appreciated.
    Last edited by kingfishmike; 02-10-2012 at 10:11 AM.

  2. #2
    Forum Guru mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    3,004

    Re: Macro to Group Data

    Try this

    Sub Test()
    For N = 2 To Cells(Rows.Count, 1).End(xlUp).Row + 1
        If Cells(N, 1) <> Cells(N - 1, 1) And N <> 2 Then
            GrowingString = GrowingString & Cells(N - 1, 2)
            Cells(Rows.Count, 8).End(xlUp).Offset(1, 0) = Cells(N - 1, 1)
            Cells(Rows.Count, 8).End(xlUp).Offset(0, 1) = GrowingString
            GrowingString = ""
        ElseIf N <> 2 Then
            GrowingString = GrowingString & Cells(N - 1, 2) & Chr$(10)
        End If
    Next N
    End Sub
    Martin

    Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.

    If my solution has saved you time and/or money, please consider donating to Cancer Research UK.

  3. #3
    Registered User
    Join Date
    02-08-2012
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro to Group Data

    mrice, thanks for the help, but so far, it is only grouping a list of the items in the "state" column in a different column. I need the document names grouped along side the document numbers they represent

  4. #4
    Registered User
    Join Date
    02-08-2012
    Location
    Florida
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Macro to Group Data

    Nevermind mrice, I tweaked it a little and got it to work. You are the man! Thanks alot

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0