Looking for help in Creating new columns with duplicate unique data

xchaserr

New Member
Joined
Mar 21, 2011
Messages
3
Hi, I have a large excel file with a ton of customer information in it. The way it is formatted however leaves me scratching my head as to how to get the information into a usable format.
Basically each customer has a unique identifier, and of course phone numbers. For some reason the formatting has duplicate unique identifiers in rows with unique phone numbers a few columns over. Basically I would like to take the unique phone numbers and create new columns, phone1, phone2 etc.
Hopefully that makes sense, and thanks for any help.

Excel 2007 Win 7
Excel Workbook
ABCDEF
1phCustIDphEmployeeIDphVendorIDphContactIDphTypephNumber
25541555-387-6457
3137615553852998
413765555477-8257
5138115553127781
66841555-727-4991
77741555-399-3420
87741555-265-6718
9138615554519580
106091555-528-4170
112961555-383-9822
128071555-457-6466
138077555-859-9588
148075555-456-0013
155631555-952-4443
165631555-312-7502
174841555-475-1010
184841555-755-4200
192891555-899-6914
202891555-258-1529
21139315553935394
225921555-
235927555-365-4792
24139615553783111
258201555-488-9271
2614001none
2714011none
28140315553396064
296251555-482-7136
306251555-475-1046
TblPhone
Excel 2007
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Can you provide the actual expected results, based on the sample data?
 
Upvote 0
xchaserr,

Welcome to the MrExcel forum.


What would you want to do with duplicate phCustID's, that have different phType's?


Excel Workbook
ABCDEF
1phCustIDphEmployeeIDphVendorIDphContactIDphTypephNumber
128071555-457-6466
138077555-859-9588
148075555-456-0013
TblPhone





Something like one of the following?


Excel Workbook
ABCDEFGH
1phCustIDphEmployeeIDphVendorIDphContactIDphTypephNumber
28071555-457-6466555-859-9588555-456-0013
3
48071,7,5555-457-6466555-859-9588555-456-0013
Results





Can we have another screenshot where you have manually created the output you are looking for?
 
Upvote 0
Hi thanks for the responses. Hiker95, thats exactly the output i was looking for. Sorry I'm not an excel guru so I tried to get my point across as best as possible. The different phtypes signify the type cell, home, work.
 
Upvote 0
xchaserr,


Sample raw data in worksheet TblPhone:


Excel Workbook
ABCDEF
1phCustIDphEmployeeIDphVendorIDphContactIDphTypephNumber
22892892892891555-899-6914
32892892892891555-258-1529
42962962962961555-383-9822
54844844844841555-475-1010
64844844844841555-755-4200
75545545545541555-387-6457
85635635635631555-952-4443
95635635635631555-312-7502
105925925925921555-
115925925925927555-365-4792
126096096096091555-528-4170
136256256256251555-482-7136
146256256256251555-475-1046
156846846846841555-727-4991
167747747747741555-399-3420
177747747747741555-265-6718
188078078078071555-457-6466
198078078078075555-456-0013
208078078078077555-859-9588
218208208208201555-488-9271
22137613761376137615553852998
2313761376137613765555477-8257
24138113811381138115553127781
25138613861386138615554519580
26139313931393139315553935394
27139613961396139615553783111
2814001400140014001none
2914011401140114011none
30140314031403140315553396064
31
TblPhone





After the macro in a new worksheet Results:


Excel Workbook
ABCDEFGH
1phCustIDphEmployeeIDphVendorIDphContactIDphTypephone1phone2phone3
22892892892891, 1555-899-6914555-258-1529
32962962962961555-383-9822
44844844844841, 1555-475-1010555-755-4200
55545545545541555-387-6457
65635635635631, 1555-952-4443555-312-7502
75925925925921, 7555-555-365-4792
86096096096091555-528-4170
96256256256251, 1555-482-7136555-475-1046
106846846846841555-727-4991
117747747747741, 1555-399-3420555-265-6718
128078078078071, 5, 7555-457-6466555-456-0013555-859-9588
138208208208201555-488-9271
1413761376137613761, 55553852998555477-8257
15138113811381138115553127781
16138613861386138615554519580
17139313931393139315553935394
18139613961396139615553783111
1914001400140014001none
2014011401140114011none
21140314031403140315553396064
22
Results





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, 03/21/2011
' http://www.mrexcel.com/forum/showthread.php?t=537729
Dim w1 As Worksheet, wR As Worksheet
Dim LR As Long, a As Long, aa As Long, SR As Long, ER As Long, H As String, LC As Long
Application.ScreenUpdating = False
Set w1 = Worksheets("TblPhone")
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=w1).Name = "Results"
Set wR = Worksheets("Results")
wR.UsedRange.Clear
Set wR = Worksheets("Results")
LR = w1.Cells(Rows.Count, 1).End(xlUp).Row
w1.Range("A2:F" & LR).Sort Key1:=w1.Range("A2"), Order1:=xlAscending, Key2:=w1.Range("E2") _
  , Order2:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
  Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
w1.Columns(1).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wR.Columns(1), Unique:=True
wR.Range("B1").Resize(, 4).Value = w1.Range("B1").Resize(, 4).Value
wR.Range("F1") = "phone1"
LR = wR.Cells(Rows.Count, 1).End(xlUp).Row
For a = 2 To LR Step 1
  H = ""
  SR = Application.Match(wR.Cells(a, 1), w1.Columns(1), 0)
  ER = Application.Match(wR.Cells(a, 1), w1.Columns(1), 1)
  wR.Range("B" & a).Resize(, 3).Value = w1.Range("B" & SR).Resize(, 3).Value
  For aa = SR To ER Step 1
    H = H & w1.Cells(aa, 5).Value & ", "
  Next aa
  If Right(H, 2) = ", " Then H = Left(H, Len(H) - 2)
  wR.Cells(a, 5) = H
  wR.Cells(a, 6).Resize(, ER - SR + 1).Value = Application.Transpose(w1.Range("F" & SR & ":F" & ER).Value)
Next a
LC = wR.Cells.Find("*", , xlValues, xlWhole, xlByColumns, xlPrevious, False).Column
For a = 7 To LC Step 1
  wR.Cells(1, a) = "phone" & a - 5
Next a
wR.Range(wR.Cells(2, 5), wR.Cells(LR, LC)).NumberFormat = "@"
wR.Range("E2:E" & LR).HorizontalAlignment = xlRight
wR.UsedRange.Columns.AutoFit
wR.Activate
Application.ScreenUpdating = True
End Sub



Then Save your workbook, Save As, a macro enabled workbook.


Then run the ReorgData macro.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,277
Members
452,902
Latest member
Knuddeluff

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