deleting duplicate rows but keeping some data

bumperjoe

New Member
Joined
Feb 4, 2006
Messages
33
i know deleting duplicate rows has been done 100x here, but i cannot get it.
if A is duplicated, can you delete the WHOLE row except the contents of B. then add the content of B on the
first occurance of A


A..............................B
FO1101144.... MAZDA/PU 94-97
FO1101144.... MAZDA/PU 98-10
FO1101144.... RANGER 93-97
FO1101144.... RANGER 98-11
to
FO1101144 .... MAZDA/PU 94-97 MAZDAPU98-10 RANGER 93-97 RANGER 98-11

thanks, joe
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
If your worksheet is set up as you say

and

your data is already sorted by column A as your post suggests

then

this macro is one way to accomplish what you are after:


Sub Test1()
Application.ScreenUpdating = False
Dim xRow&, area As Range, cell As Range
For xRow = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
If Cells(xRow, 1).Value <> Cells(xRow - 1, 1).Value Then _
Rows(xRow).Resize(1).Insert
Next xRow
Columns(1).Insert
For Each area In Columns(2).SpecialCells(2).Areas
With Cells(area.Row, 1)
For Each cell In area.Offset(0, 1).Resize(area.Rows.Count, 1)
.Value = .Value & " " & cell.Value
Next cell
.Value = area.Cells(1, 1).Value & .Value
End With
Next area
Columns(1).SpecialCells(4).EntireRow.Delete
Columns(1).AutoFit
Range(Columns(2), Columns(3)).Delete
Application.ScreenUpdating = True
End Sub
 
Upvote 0
it says this line needs debuging ?

Rows(xRow).Resize(1).Insert


If your worksheet is set up as you say

and

your data is already sorted by column A as your post suggests

then

this macro is one way to accomplish what you are after:


Sub Test1()
Application.ScreenUpdating = False
Dim xRow&, area As Range, cell As Range
For xRow = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
If Cells(xRow, 1).Value <> Cells(xRow - 1, 1).Value Then _
Rows(xRow).Resize(1).Insert
Next xRow
Columns(1).Insert
For Each area In Columns(2).SpecialCells(2).Areas
With Cells(area.Row, 1)
For Each cell In area.Offset(0, 1).Resize(area.Rows.Count, 1)
.Value = .Value & " " & cell.Value
Next cell
.Value = area.Cells(1, 1).Value & .Value
End With
Next area
Columns(1).SpecialCells(4).EntireRow.Delete
Columns(1).AutoFit
Range(Columns(2), Columns(3)).Delete
Application.ScreenUpdating = True
End Sub
 
Upvote 0
It all worked when I tested it so something else is going on. Are there any merged cells involved (look closely), and are you sure the original data on the sheet is in column A and column B. Or sis the sheet protected...you did not say what the error number was.
 
Upvote 0
should i highlight just A and B or all the columns. i tried it both ways and it just groups the same numbers together with empty rows above and below the groups of duplicate numpers
 
Upvote 0
You don't highlight anything. You just activate the worksheet holding the data and run the macro, which you would place in a standard module.
 
Upvote 0
By the way, I tested the macro using your posted data along with other sample data I created, so I know it works under normal circumstances. Something is happening with your workbook that is causing the error.
 
Upvote 0
it says run time error 1004

Application.ScreenUpdating = False
Dim xRow&, area As Range, cell As Range
For xRow = Cells(Rows.Count, 1).End(xlUp).Row To 2 Step -1
If Cells(xRow, 1).Value <> Cells(xRow - 1, 1).Value Then _
it points to this line .........Rows(xRow).Resize(1).Insert
Next xRow
Columns(1).Insert
 
Upvote 0
• Is the sheet protected.
• Are any rows or columns hidden.
• Are any cells merged.
• Is it really column A and column B that the data resides in.
• I am assuming the data is all constants, no formulas.

The code works with normal data such as you posted. Take a close look at your worksheet to see which item(s) above are causing the error.
 
Upvote 0

Forum statistics

Threads
1,203,618
Messages
6,056,320
Members
444,858
Latest member
ucbphd

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