Unique values from rows combined into single row

kravspelunker

New Member
Joined
Jan 8, 2008
Messages
10
Hey all, I apologize if this is an easy topic that I've missed elsewhere in the forums but I haven't had much luck in finding anything.

I have a large spreadsheet that has lots of information that repeats various information in different rows. What I would like to do is to collect all of this information from multiple rows in the spreadsheet into a single row whose cells contain all of the information from all other rows but without any of the repeating. I'm having some difficulty even articulating what I need help with so I've put a quick example of what I am trying to accomplish below. I appreciate your help and responses. Please let me know if I have provided sufficient information.
Many thanks!

Current example:

Row1 Row2 Row3 Row4
machineA unique_value1 FacilityA AppA
machineB unique_value2 FacilityB AppB
machineC unique_value3 FacilityC AppA
machineA unique_value1 FacilityC AppB
machineA unique_value1 FacilityC AppC

Desired result:

Row1 Row2 Row3 Row4
machineA unique_value1 FacilityA, FacilityC AppA, AppC, AppB
machineB unique_value2 FacilityB ApplicationB
machineC unique_value3 FacilityC ApplicationA
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
kravspelunker,

It is difficult to determine by your post where your raw data actually is?

What version of Excel are you using?

You will generally get much more help (and faster) in this forum if you can post your small samples (what you have and what you expect to achieve) directly in the forum.

To attach screenshots, see below in my Signature block: Post a screen shot with one of these:
 
Upvote 0
Excel Workbook
ABCD
1Current Data:
2
3MachineIPApplicationFacility
4
5MachineAxxx.yyy.100.1App_AFacility_1
6MachineBxxx.yyy.100.2App_CFacility_2
7MachineCxxx.yyy.100.3App_BFacility_3
8MachineAxxx.yyy.100.1App_BFacility_2
9MachineAxxx.yyy.100.1App_BFacility_1
10MachineDxxx.yyy.100.4App_AFacility_3
11
12
13Desired Result:
14
15MachineIPApplicationFacility
16
17MachineAxxx.yyy.100.1App_A, App_BFacility_1, Facility_2
18MachineBxxx.yyy.100.2App_CFacility_2
19MachineCxxx.yyy.100.3App_BFacility_3
20MachineDxxx.yyy.100.4App_AFacility_3
Sheet3
Excel 2007
 
Upvote 0
Hiker95, I think this is what you were asking me for. Thanks for the heads up and please let me know if this is sufficient.
Many thanks!
 
Upvote 0
Not exactly what you are looking for but perhaps very close, this as close as I could come up with, Again I know this is not quite in the format you wanted.

Excel Workbook
ABCDEFGHIJKL
1************
21Current Data:**********
32******Unique MachinesIP-AddressFacilities**
43MachineIPApplicationFacility**MachineAxxx.yyy.100.1App_A,Facility_1App_B,Facility_2App_B,Facility_1
54******MachineBxxx.yyy.100.2App_C,Facility_2**
65MachineAxxx.yyy.100.1App_AFacility_1**MachineCxxx.yyy.100.3App_B,Facility_3**
76MachineBxxx.yyy.100.2App_CFacility_2**MachineDxxx.yyy.100.4App_A,Facility_3**
87MachineCxxx.yyy.100.3App_BFacility_3*******
98MachineAxxx.yyy.100.1App_BFacility_2*******
109MachineAxxx.yyy.100.1App_BFacility_1*******
1110MachineDxxx.yyy.100.4App_AFacility_3*******
12************
Sheet2
 
Last edited:
Upvote 0
kravspelunker,

I assume that your actual raw data titles are in row 1.


Sample raw data before the macro:


Excel Workbook
ABCDEFGHIJ
1MachineIPApplicationFacility
2
3MachineAxxx.yyy.100.1App_AFacility_1
4MachineBxxx.yyy.100.2App_CFacility_2
5MachineCxxx.yyy.100.3App_BFacility_3
6MachineAxxx.yyy.100.1App_BFacility_2
7MachineAxxx.yyy.100.1App_BFacility_1
8MachineDxxx.yyy.100.4App_AFacility_3
9
Sheet3





After the macro:


Excel Workbook
ABCDEFGHIJ
1MachineIPApplicationFacilityMachineIPApplicationFacility
2
3MachineAxxx.yyy.100.1App_AFacility_1MachineAxxx.yyy.100.1App_A, App_B, App_BFacility_1, Facility_1, Facility_2
4MachineAxxx.yyy.100.1App_BFacility_1MachineBxxx.yyy.100.2App_CFacility_2
5MachineAxxx.yyy.100.1App_BFacility_2MachineCxxx.yyy.100.3App_BFacility_3
6MachineBxxx.yyy.100.2App_CFacility_2MachineDxxx.yyy.100.4App_AFacility_3
7MachineCxxx.yyy.100.3App_BFacility_3
8MachineDxxx.yyy.100.4App_AFacility_3
9
Sheet3





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub ReorgData()
' hiker95, 07/11/2011
' http://www.mrexcel.com/forum/showthread.php?t=563514
Dim LR As Long, a As Long, SR As Long, ER As Long
Application.ScreenUpdating = False
LR = Cells(Rows.Count, 1).End(xlUp).Row
With ActiveSheet.Sort
  With .SortFields
    .Clear
    .Add Key:=Range("A3:A" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    .Add Key:=Range("B3:B" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    .Add Key:=Range("C3:C" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    .Add Key:=Range("D3:D" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  End With
  .SetRange Range("A3:D" & LR)
  .Apply
End With
With Range("E3:E" & LR)
  .FormulaR1C1 = "=RC[-4]&RC[-3]"
  .Value = .Value
End With
Columns("A:B").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("G1"), Unique:=True
Range("J1:K1").Value = Range("C1:D1").Value
LR = Cells(Rows.Count, 7).End(xlUp).Row
With Range("I3:I" & LR)
  .FormulaR1C1 = "=RC[-2]&RC[-1]"
  .Value = .Value
End With
For a = 3 To LR Step 1
  SR = Application.Match(Cells(a, 9), Columns(5), 0)
  ER = Application.Match(Cells(a, 9), Columns(5), 1)
  If SR = ER Then
    Range("J" & a).Value = Range("C" & SR).Value
    Range("K" & a).Value = Range("D" & SR).Value
  Else
    Range("J" & a).Value = Join(Application.Transpose(Range("C" & SR & ":C" & ER)), ", ")
    Range("K" & a).Value = Join(Application.Transpose(Range("D" & SR & ":D" & ER)), ", ")
  End If
Next a
Columns(5).ClearContents
Columns(9).Delete
Columns("G:J").AutoFit
Application.ScreenUpdating = True
End Sub


Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm


Then run the ReorgData macro.
 
Upvote 0
snoopyhr, I have been unable to decipher what exactly the formulas are doing, even when stepping through them, so that I could expand them to account for my whole spreadsheet. When plugged in to the small sample that they cover, however, the results are most helpful. How do I expand the scope of what these formulas are looking at? I know it sounds like a dumb question (and most likely since I've asked it, it is) but every time I try to change them to look at a larger area, I get no data back.

hiker95, the macro also summarizes all of the data that I am after but the cells have tons of repeat information when I plug it in. (for example, cell c3 might have "application_A, application_A, Application_A, Application_B, Application_C". Do you have any suggestion on what I might do to eliminate the repeats?

Both of you, thank you so much for taking a look at my problem and helping me out.
 
Upvote 0
kravspelunker,

Are you looking to eliminate duplicates in individual cells in columns I and J?


I3 displayes:
App_A, App_B, App_B

You are looing for?
App_A, App_B


J3 displayes:
Facility_1, Facility_1, Facility_2

You are looing for?
Facility_1, Facility_2
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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