Sort list into Groups by Cell (Non repeating Columns)

ccn2623

New Member
Joined
Oct 8, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
HI

I have been trying to group data, not like grouping under the Data Tab or Analyse, but take a list and group in this case by the 1st and 2nd column, but not keep repeating the value down the list values.

Included are 2 images, 1st is the data, 2nd is how i would like the output to look.

Essentially grouping on 1st and 2nd column and listing the 3rd column

Many thanks for any advice

Chris
 

Attachments

  • Capture1.PNG
    Capture1.PNG
    74.2 KB · Views: 11
  • Capture2.PNG
    Capture2.PNG
    35.9 KB · Views: 11

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try this on a copy of your data.

VBA Code:
Option Explicit
Sub Group_Data()
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")   '<<< change to actual sheet name
    
    Dim Str1 As String, Str2 As String
    Str1 = ws.Range("A1")
    Str2 = ws.Range("B1")
    
    Dim i As Long, Arr
    Arr = ws.Range("A1").CurrentRegion
    
    For i = 2 To UBound(Arr, 1)
        If Arr(i, 1) = Str1 Then Arr(i, 1) = "" Else Str1 = Arr(i, 1)
        If Arr(i, 2) = Str2 Then Arr(i, 2) = "" Else Str2 = Arr(i, 2)
    Next i
    
    ws.Range("A1").Resize(UBound(Arr, 1), UBound(Arr, 2)).Value = Arr
End Sub

Before
ccn2623.xlsm
ABC
1Entity NameProcess NameResource Item Name
2Commercial - London Commercial - LondonLondon MarketCQE
3Commercial - London Commercial - LondonLondon MarketAXCO
4Commercial - London Commercial - LondonLondon MarketKITE
5Commercial - London Commercial - LondonLondon MarketRSAred
6Commercial - London Commercial - LondonLondon MarketScribe
7Commercial - London Commercial - LondonLondon MarketCSS
8Commercial - London Commercial - LondonLondon MarketDART
9Commercial - London Commercial - LondonLondon MarketGeoRisk Portfolio
10Commercial - London Commercial - LondonLondon MarketInternet
11Commercial - London Commercial - LondonLondon MarketMS DYNAMICS
12Commercial - London Commercial - LondonLondon MarketMS Outlook
13Commercial - London Commercial - LondonLondon MarketGalaxy
14Commercial - London Commercial - LondonLondon MarketSharepoint
15Commercial - London Commercial - LondonLondon MarketWIP Pricing Tool
16Commercial - London Commercial - LondonGlobal NetworkAXCO
17Commercial - London Commercial - LondonGlobal NetworkInformation Platform
18Commercial - London Commercial - LondonGlobal NetworkLexis Nexis
19Commercial - London Commercial - LondonGlobal NetworkMS Outlook
20Commercial - London Commercial - LondonGlobal NetworkCQE
21Commercial - London Commercial - LondonGlobal NetworkGalaxy
22Commercial - London Commercial - LondonGlobal NetworkGeoRisk Portfolio
23Commercial - London Commercial - LondonGlobal NetworkInternet
24Commercial - London Commercial - LondonGlobal NetworkKITE
25Commercial - London Commercial - LondonGlobal NetworkSharepoint
26Commercial - Motability Operations - LiverpoolCustomer Service TelephonyCUE
27Commercial - Motability Operations - LiverpoolCustomer Service TelephonyIEX WORKFORCE MANAGEMENT
28Commercial - Motability Operations - LiverpoolCustomer Service TelephonyInternet
29Commercial - Motability Operations - LiverpoolCustomer Service TelephonyMMR VERINT
30Commercial - Motability Operations - LiverpoolCustomer Service TelephonyRespond
31Commercial - Technical Claims - LiverpoolThird Party RecoveriesCCS
32Commercial - Technical Claims - LiverpoolThird Party RecoveriesInternet
33Commercial - Technical Claims - LiverpoolThird Party RecoveriesRespond
34
Sheet1


After
ccn2623.xlsm
ABC
1Entity NameProcess NameResource Item Name
2Commercial - London Commercial - LondonLondon MarketCQE
3AXCO
4KITE
5RSAred
6Scribe
7CSS
8DART
9GeoRisk Portfolio
10Internet
11MS DYNAMICS
12MS Outlook
13Galaxy
14Sharepoint
15WIP Pricing Tool
16Global NetworkAXCO
17Information Platform
18Lexis Nexis
19MS Outlook
20CQE
21Galaxy
22GeoRisk Portfolio
23Internet
24KITE
25Sharepoint
26Commercial - Motability Operations - LiverpoolCustomer Service TelephonyCUE
27IEX WORKFORCE MANAGEMENT
28Internet
29MMR VERINT
30Respond
31Commercial - Technical Claims - LiverpoolThird Party RecoveriesCCS
32Internet
33Respond
34
Sheet1
 
Upvote 0
Probably safer with a Sort done first...

VBA Code:
Option Explicit
Sub Group_Data_2()
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")   '<<< change to actual sheet name
    
    ws.Columns("A:C").Sort Key1:=ws.Range("A1"), order1:=xlAscending, Key2:=ws.Range("B1"), order2:=xlAscending, Header:=xlYes
    
    Dim Str1 As String, Str2 As String
    Str1 = ws.Range("A1")
    Str2 = ws.Range("B1")
    
    Dim i As Long, Arr
    Arr = ws.Range("A1").CurrentRegion
    
    For i = 2 To UBound(Arr, 1)
        If Arr(i, 1) = Str1 Then Arr(i, 1) = "" Else Str1 = Arr(i, 1)
        If Arr(i, 2) = Str2 Then Arr(i, 2) = "" Else Str2 = Arr(i, 2)
    Next i
    
    ws.Range("A1").Resize(UBound(Arr, 1), UBound(Arr, 2)).Value = Arr
End Sub
 
Upvote 0
Solution
Probably safer with a Sort done first...

VBA Code:
Option Explicit
Sub Group_Data_2()
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")   '<<< change to actual sheet name
   
    ws.Columns("A:C").Sort Key1:=ws.Range("A1"), order1:=xlAscending, Key2:=ws.Range("B1"), order2:=xlAscending, Header:=xlYes
   
    Dim Str1 As String, Str2 As String
    Str1 = ws.Range("A1")
    Str2 = ws.Range("B1")
   
    Dim i As Long, Arr
    Arr = ws.Range("A1").CurrentRegion
   
    For i = 2 To UBound(Arr, 1)
        If Arr(i, 1) = Str1 Then Arr(i, 1) = "" Else Str1 = Arr(i, 1)
        If Arr(i, 2) = Str2 Then Arr(i, 2) = "" Else Str2 = Arr(i, 2)
    Next i
   
    ws.Range("A1").Resize(UBound(Arr, 1), UBound(Arr, 2)).Value = Arr
End Sub
Thank you so much, worked a treat ! Most grateful :)
 
Upvote 0
Happy to help, and welcome to the forum 🙂
Oooo Advancing on from your solution, I was wondering if the Data related to the values in column "A1" could be written into separate Tabs?
I have now got to email the persons in Col "F" & "G" the list of what they are responsible for, so thought it may be better to write to individual tabs or perhaps there is a better solution/idea?
 

Attachments

  • Capture_New.PNG
    Capture_New.PNG
    60.4 KB · Views: 2
Upvote 0
Oooo Advancing on from your solution, I was wondering if the Data related to the values in column "A1" could be written into separate Tabs?
I have now got to email the persons in Col "F" & "G" the list of what they are responsible for, so thought it may be better to write to individual tabs or perhaps there is a better solution/idea?
It's certainly possible to create new sheets for each group in column A, however that is considerably more (and different) from your original post, and therefore warrants a new question. (And don't forget to mark answers that do what you asked for as a 'Solution' 😉)
Create a new question and I'll watch out for it - although I won't get to it for a while, by which time another volunteer on the forum could have solved it for you.
 
Upvote 0
It's certainly possible to create new sheets for each group in column A, however that is considerably more (and different) from your original post, and therefore warrants a new question. (And don't forget to mark answers that do what you asked for as a 'Solution' 😉)
Create a new question and I'll watch out for it - although I won't get to it for a while, by which time another volunteer on the forum could have solved it for you.
Ah got it, found the solution button (Done)
Ill create a new question. Thank you again for your help :)
 
Upvote 0

Forum statistics

Threads
1,215,230
Messages
6,123,752
Members
449,118
Latest member
kingjet

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