Macro - Deleting Duplicate Cell Content

Gessen

New Member
Joined
Sep 20, 2011
Messages
14
Hi Guys,

Conceptually this doesn't sound too crazy to me, I just don't know VBA. So I could really use your help! I need a Macro to delete duplicate cell content (String) within a column section, until it hits an empty ("") cell, with a starting cell based off of a specified column and row number. Can anyone help me put something together? I've got a sheet that pulls a lot of data from other sheets and creates some duplicate content. I just want to be able to clean them up. The duplicate content might not be one after another. The duplicate may be at the opposite end of the list. Thanks for your help!

-Gessen
 
Sub DeleteDuplicate()
Dim RowNo As Long
Dim ColNo As Long
Dim PrevCell As String

Dim ws As Worksheet

ColNo = 3 ' Column to check for Duplicates

'Need to sort the column prior to proceeding

Set ws = ThisWorkbook.Worksheets(1)

RowNo = 1
PrevCell = Trim(ws.Cells(RowNo, ColNo))
RowNo = RowNo + 1
Do While Len(Trim(ws.Cells(RowNo, ColNo))) > 0
If Trim(ws.Cells(RowNo, ColNo)) = PrevCell Then
ws.Cells(RowNo, ColNo).Delete Shift:=xlUp
End If
PrevCell = ws.Cells(RowNo, ColNo)
RowNo = RowNo + 1
Loop
End Sub
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,215,429
Messages
6,124,834
Members
449,192
Latest member
mcgeeaudrey

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