[Help] To eliminate almost identical datas to be 1 & merge the differences among them

Gravity101

New Member
Joined
Aug 12, 2011
Messages
9
Hey guys, really need help from you with my excel work, and looks like i stuck in this point.:(:(

So i have a sheet, contains many datas.
The key of every row is No.PEB.
so the situation is like here :
i have a row the No.PEB is ex: 037175, this row has like more than 20 columns.

the problem is i have 3 rows of No.PEB with number 037175 the only difference is the last column of every row is different,

and i want to eliminate them, and merge the difference to be only one row.


Ugh, i don;t think i explain it well, so the exmple is here:


No.PEB------------Date-----------------Documents----------------CodeOfDocs


037175-------------7/7/11---------------AWB-------------------------12345

037175-------------7/7/11---------------BL-----------------------------85858

037175-------------7/7/11---------------Invoice-----------------------54765


nah, i want to make it to be


No.PEB------------Date-----------------AWB-----------------BL-------------------Invoice


037175-------------7/7/11---------------12345-------------85858------------------54765



thanks in advance guys.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Gravity101,


Thank you for the workbook.


Sample raw data in worksheet "Sheet 1" (not all columns are shown for brevity):


Excel Workbook
ABXY
1NO_PEBTGL_PEBNama DokumenNO_DOK
203717502/17/2010 00:00:00AWBSRG7ABZ277
303717502/17/2010 00:00:00INVOICEPMS-042-2010
403717502/17/2010 00:00:00PACKING LISTPMS-042-2010
503787002/18/2010 00:00:00AWBSRG7ABZ304
603787002/18/2010 00:00:00INVOICEPMS-044-2010
703787002/18/2010 00:00:00PACKING LISTPMS-044-2010
803983502/20/2010 00:00:00AWBSRG7ABZ355
903983502/20/2010 00:00:00INVOICEPMS-048-2010
1003983502/20/2010 00:00:00PACKING LISTPMS-048-2010
1104243602/24/2010 00:00:00AWBSRG7ABZ417
1204243602/24/2010 00:00:00INVOICEPMS-053-2010
1304243602/24/2010 00:00:00PACKING LISTPMS-053-2010
1404249602/24/2010 00:00:00AWBSRG7ABZ446
1504249602/24/2010 00:00:00INVOICEPMS-054-2010
1604249602/24/2010 00:00:00PACKING LISTPMS-054-2010
1704391702/25/2010 00:00:00AWBSRG7ABZ529
1804391702/25/2010 00:00:00INVOICEPMS-058-2010
1904391702/25/2010 00:00:00PACKING LISTPMS-058-2010
2004391702/25/2010 00:00:00AWBSRG7ABZ529
2104391702/25/2010 00:00:00INVOICEPMS-058-2010
2204391702/25/2010 00:00:00PACKING LISTPMS-058-2010
2304391702/25/2010 00:00:00AWBSRG7ABZ529
2404391702/25/2010 00:00:00INVOICEPMS-058-2010
2504391702/25/2010 00:00:00PACKING LISTPMS-058-2010
2604391702/25/2010 00:00:00AWBSRG7ABZ529
2704391702/25/2010 00:00:00INVOICEPMS-058-2010
2804391702/25/2010 00:00:00PACKING LISTPMS-058-2010
2904410602/25/2010 00:00:00AWBSRG7ABZ527
3004410602/25/2010 00:00:00INVOICEPMS-057-2010
Sheet 1





After the macro in a new worksheet Results (not all rows shown for brevity):


Excel Workbook
ABCDEFGH
1NO_PEBTGL_PEBNO Nama DokumenAWBB/LINVOICELetter Of Credit (L/C)PACKING LIST
203717502/17/2010 00:00:00SRG7ABZ277PMS-042-2010PMS-042-2010
504243602/24/2010 00:00:00SRG7ABZ417PMS-053-2010PMS-053-2010
2100005701/02/2010 00:00:00NYKS3140174560PMS-207-2009PMS-207-2009
6000557801/22/2010 00:00:00MSCUJK395729PMS-013-2010CI0110.35553PMS-013-2010
6100564101/22/2010 00:00:00AHL/20/SMG/ZEE/10/0127PMS-016-2010PMS-016-2010
7400819101/30/2010 00:00:00550390599PMS-023-2010PMS-023-2010
7500827301/30/2010 00:00:00PTYSRG/SYD-016PMS-022-2010PMS-022-2010
7600850802/01/2010 00:00:00PMS-025-2010PMS-025-2010
7700852802/01/2010 00:00:00NYKS3140044140PMS-024-2010PMS-024-2010
8400984802/05/2010 00:00:0049030303002011APMS-031-2010PMS-031-2010
8500992402/06/2010 00:00:00PMS-042-2010PMS-042-2010
8601000002/07/2011 00:00:00NYKS3140068380PMS-037-2011PMS-037-2011
8701001902/07/2011 00:00:00MOLU14600468521PMS-036-2011PMS-036-2011
8801010502/08/2010 00:00:00550493757PMS-034-2010PMS-034-2010
8901028202/08/2010 00:00:00PMS-035-2010PMS-035-2010
9001074002/09/2010 00:00:00PTYSRG/BNE-021PMS-038-2010PMS-038-2010
9101074302/09/2010 00:00:00PTYSRG/SYD-019PMS-037-2010PMS-037-2010
9209267611/27/2010 00:00:00PMS-289-2010024CDI2717PMS-289-2010
9309298611/29/2010 00:00:00PMS-293-2010PMS-293-2010
9409303611/29/2010 00:00:00PMS-291-2010PMS-291-2010
9509303711/29/2010 00:00:00PMS-292-2010PMS-292-2010
9609377212/24/2009 00:00:00SRMFOSB00683PMS-202-2009PMS-202-2009
9709382712/24/2009 00:00:00SRMSKGB00684PMS-203-2009PMS-203-2009
9809414012/02/2010 00:00:00PMS-294-2010PMS-294-2010
9909416512/28/2009 00:00:004903-0303-912.016.APMS-205-2009L3017CI001623/09PMS-205-2009
10009418112/28/2009 00:00:004903-0303-912.016.BPMS-206-200900762ECD09001126PMS-206-2009
10109463112/03/2010 00:00:00PMS-295-2010PMS-295-2010
10209483212/04/2010 00:00:00ID1301680PMS-296-2010PMS-296-2010
12210297112/31/2010 00:00:00AHL/20/SMG/ANR/11/0003PMS-002-2011PMS-002-2011
12390027706/21/2010 00:00:002922/DJ-DAGLU/ETPIK/071/JGW/VIII/10071/JGW/VIII/10
124
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, 08/13/2011
' http://www.mrexcel.com/forum/showthread.php?t=571512
Dim w1 As Worksheet, wR As Worksheet
Dim LR As Long, LR2 As Long, a As Long, aa As Long, SR As Long, ER As Long, FC As Long
Application.ScreenUpdating = False
Set w1 = Worksheets("Sheet 1")
w1.AutoFilterMode = False
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=w1).Name = "Results"
Set wR = Worksheets("Results")
wR.UsedRange.Clear
w1.Columns("A:B").Copy wR.Columns("A:B")
w1.Columns("X:Y").Copy wR.Columns("C:D")
w1.UsedRange.AutoFilter
LR = wR.Cells(Rows.Count, "A").End(xlUp).Row
With wR.Range("E2:E" & LR)
  .FormulaR1C1 = "=RC[-4]&RC[-3]"
  .Value = .Value
End With
wR.Columns("A:B").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wR.Columns("G:H"), Unique:=True
wR.Columns("C:C").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wR.Columns("L:L"), Unique:=True
LR = wR.Cells(Rows.Count, "G").End(xlUp).Row
With wR.Range("I2:I" & LR)
  .FormulaR1C1 = "=RC[-2]&RC[-1]"
  .Value = .Value
End With
LR = wR.Cells(Rows.Count, "L").End(xlUp).Row
wR.Range("L2:L" & LR).Sort Key1:=wR.Range("L2"), Order1:=1, Header:=xlNo
wR.Range("M1").Resize(, LR - 1).Value = Application.Transpose(Range("L2:L" & LR))
wR.Range("L1:L" & LR).Clear
LR2 = wR.Cells(Rows.Count, "I").End(xlUp).Row
With wR.Range("J2:J" & LR2)
  .FormulaR1C1 = "=MATCH(RC[-1],C[-5],0)"
  .Value = .Value
End With
LR = wR.Cells(Rows.Count, "A").End(xlUp).Row
With wR.Range("K2:K" & LR2 - 1)
  .FormulaR1C1 = "=R[1]C[-1]-1"
  .Value = .Value
End With
wR.Range("K" & LR2) = LR
LR = wR.Cells(Rows.Count, "G").End(xlUp).Row
For a = 2 To LR Step 1
  SR = wR.Range("J" & a)
  ER = wR.Range("K" & a)
  For aa = SR To ER Step 1
    If wR.Range("C" & aa) = "" Then
      wR.Range("L" & a) = wR.Range("D" & aa)
    Else
      FC = 0
      On Error Resume Next
      FC = Application.Match(wR.Range("C" & aa), wR.Rows(1), 0)
      On Error GoTo 0
      If FC > 0 Then wR.Cells(a, FC) = wR.Range("D" & aa)
    End If
  Next aa
Next a
wR.Columns("I:K").Delete
wR.Columns("A:F").Delete
If Application.CountA(wR.Range("C:C")) = 0 Then
  wR.Columns("C:C").Delete
Else
  wR.Range("C1") = "NO Nama Dokumen"
End If
wR.Range("A1:B1").Interior.ColorIndex = xlNone
wR.UsedRange.Columns.AutoFit
wR.Activate
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

Forum statistics

Threads
1,224,602
Messages
6,179,844
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