Finding duplicates and merging them

jrnyman

Board Regular
Joined
Mar 10, 2002
Messages
105
I have a column where many of the names will be repeated consecutively (after sorting). I want to use VBA to find a set of replicates and merge them into one cell. Any idea?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi jrnyman

You could try this code in a macro:

Application.DisplayAlerts = False
For Each Cell In Selection
If ActiveCell.Offset(1, 0).Value = ActiveCell.Value Then
Range(ActiveCell, ActiveCell.Offset(1, 0)).Merge
Else
ActiveCell.Offset(1, 0).Select
End If
Next
End Sub

This seems to do what you want, but test it out first. Be careful because it will merge blank cells if they are in your selection. Particularly make sure the last cell in your selection is not blank (or it will merge right down the column). Don't forget you can't use the undo button with a macro.

Hope this helps
regards
Derek
This message was edited by Derek on 2002-03-13 06:00
 
Upvote 0

Forum statistics

Threads
1,214,551
Messages
6,120,161
Members
448,948
Latest member
spamiki

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