Grouping data

Status
Not open for further replies.

Rbd340

New Member
Joined
Oct 11, 2017
Messages
13
Hi,
I'm looking for a way to concatenate vertically based on column A and B and put it in a new tab:
Basically my data looks like this:

Column1 Column2 Column3
A 1 DataXx
A 1 DataAA
A 1 DataBB
A 2 DataXx
A 2 DataCc
A 2 DataAA
B 1 DataCC
B 1 DataAA
B 1 DataFF
B 1 DataWW
B 2 DataRR
B 2 DataXX

and the preferred output would
Column1 Column2 Column3
A 1 DataXx,DataAA,DataBB
B 2 DataXx,DataCc,DataAA
A 1 DataCC,DataAA,DataFF,DataWW
B 2 DataRR,DataXX

Anyone kind enough to help me with this? The excel changes in length and values in column 1 and 2 can have different numbers of rows.
I have to do this a lot and it would help if I have a macro.

Thanks a lot in advance!
 
I can not reproduce such errors or understand how that could happen if the active sheet has its data in columns A:C. If you are still having that problem with a particular sheet's data, could you upload that sheet as an actual file to a public file-share site (eg Dropbox) and provide a link here to that file so we could take a look at it and see if the same happens to us?

The code ran fine for me on the sample data that you provided in your previous post.

Hi Peter,

Here is the an example of a file where the issue occurs when I run the script:
https://www.dropbox.com/s/oakikhfw8xi4v9n/Example.xlsx?dl=0

Kind regards,
Ricardo
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Here is the an example of a file where the issue occurs when I run the script:
Thanks. Looking back, I should probably have asked you about the size of the data - 500,000+ rows is rather large! :)

Try this version.
Code:
Sub CombineData_v2()
  Dim a As Variant, b As Variant
  Dim i As Long, r As Long
  
  a = Range("A1", Range("C" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 3)
  r = 1
  For i = 2 To UBound(a)
    If a(i, 1) <> a(i - 1, 1) Or a(i, 2) <> a(i - 1, 2) Then
      r = r + 1
      b(r, 1) = a(i, 1): b(r, 2) = a(i, 2): b(r, 3) = a(i, 3)
    Else
      b(r, 3) = a(r, 3) & "," & a(i, 3)
    End If
  Next i
  Application.ScreenUpdating = False
  With Sheets.Add(After:=ActiveSheet)
    With .Range("A1:C1").Resize(r)
      .Value = b
      .Rows(1).Value = Application.Index(a, 1, 0)
      .Columns.AutoFit
    End With
  End With
  Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Thanks. Looking back, I should probably have asked you about the size of the data - 500,000+ rows is rather large! :)

Try this version.
[/code]

Maybe I should have told you that as well :laugh:
Unfortunately the formula doesn't quite work yet, it does set the headers correctly now and makes a third column but it doesn't put all accounts in the third column.

For Example, SubscriptionID 19, UserID 38216643 shows only 2 accounts, where I would expect 43 accounts. Looking at the files his output is the last account of the user above him and his own last account.
 
Upvote 0
I did have a typo in my last code, it should have been
Rich (BB code):
    Else
      b(r, 3) = b(r, 3) & "," & a(i, 3)
    End If

However, that will not solve your problem. :(

I believe that you are running foul of one (or more) of Excel's limits. For example, there is a limit of how many characters a cell can hold (32,767). For one example in your sample data (A=11563, B =34671499) there are over 2,200 rows. The concatenation of the column C values for these rows would produce a string of about 80,000 characters, more than double what a cell will hold! I believe there are other sets of rows with similar circumstances.

It does make me wonder, even if it was possible to put such values into a cell, what you intend to do with those cells? They would be pretty meaningless to look at. :eek:
 
Last edited:
Upvote 0
I did have a typo in my last code, it should have been
Rich (BB code):
    Else
      b(r, 3) = b(r, 3) & "," & a(i, 3)
    End If

However, that will not solve your problem. :(

I believe that you are running foul of one (or more) of Excel's limits. For example, there is a limit of how many characters a cell can hold (32,767). For one example in your sample data (A=11563, B =34671499) there are over 2,200 rows. The concatenation of the column C values for these rows would produce a string of about 80,000 characters, more than double what a cell will hold! I believe there are other sets of rows with similar circumstances.

It does make me wonder, even if it was possible to put such values into a cell, what you intend to do with those cells? They would be pretty meaningless to look at. :eek:

Thank you I wasn't aware of this.
What I'm trying to do is group the users (column2) that have access to the same accounts (column 3) within the same subscription (column1).
I have multiple sheets about the same users (sheet for account settings, sheet for permissions, sheet for sign limits etc.) and only when the users all have the same info I can group them together.
The idea was to group all the data for each user in one cell so that I can compare them but unfortunately it seems like this won't work.

Do you per chance have a solution how to circumvent this?
 
Upvote 0
What I'm trying to do is group the users (column2) that have access to the same accounts (column 3) within the same subscription (column1).

.. only when the users all have the same info I can group them together.
Your original sample and expected results seems to me to be grouping the accounts (columns 3) not the users (column 2).
If you are trying to group the users that have the same info, then for the original sample data, would it not be something like this? (I have highlighted some to try to show how I have grouped them)


Book1
ABCDEFG
1Subscription IDUser_IDAccountAccountSubscription IDUser
2A1DataXxDataXxA1,2
3A1DataAADataAAA1,2
4A1DataBBDataBBA1
5A2DataXxDataCcA2
6A2DataCcDataCCB1
7A2DataAADataAAB1
8B1DataCCDataFFB1
9B1DataAADataWWB1
10B1DataFFDataRRB2
11B1DataWWDataXXB2
12B2DataRR
13B2DataXX
Sheet9
 
Upvote 0
Your original sample and expected results seems to me to be grouping the accounts (columns 3) not the users (column 2).
If you are trying to group the users that have the same info, then for the original sample data, would it not be something like this? (I have highlighted some to try to show how I have grouped them)

Hi Peter,

In the below link is what I'm trying to accomplish.
https://www.dropbox.com/s/v01i7rnszf851id/Example file.xlsx?dl=0

For each sheet in the workbook (except Output) I need to check if the users's permissions and settings are the same, if so, I need to group them.
I wanted to use your script to combine the data from the 'account permission' sheet into one cell per user & subscription combination. Then add the data from 'general permissions' and 'personal settings' to that cell and then compare them. If I find a match then I can group the user.
 
Upvote 0
Given the descriptions and various data samples, it's still not clear (maybe just to me) what the input looks like or what the expected output should be. Having said that, the structured nature of the data seems to lend itself to a PivotTable solution...

Excel Workbook
ABCDEFGHIJKLMNOP
1Sample DataPivotTable
2Subscription IDUsernumberAccountSingle1Single2Jointly1Jointly2AccountSubscription IDUsernumberCount of Single1Count of Single2Count of Jointly1Count of Jointly2
31002222UA012345NL97XXXX1YNYNNL97XXXX11002222UA0123451111
41002222UA012345NL97XXXX3YNYNUA1234561111
51002222UA012345NL97XXXX2YNYNNL97XXXX21002222UA0123451111
61002222UA012345NL97XXXX4YNYNUA1234561111
71002222UA123456NL97XXXX1YNYNNL97XXXX31002222UA0123451111
81002222UA123456NL97XXXX3YNYNUA1234561111
91002222UA123456NL97XXXX2YNYNNL97XXXX41002222UA0123451111
101002222UA123456NL97XXXX4YNYNUA1234561111
111002222UA123457NL97XXXX5YYYNNL97XXXX51002222UA1234571111
121002223UA123457NL97XXXX5YYYN1002223UA1234571111
Sheet1
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top