Take selection validate and delete

hobo

New Member
Joined
Nov 2, 2005
Messages
4
Hey guys,

Dunno if this is an easy one for you excel guru's out there but i'll give it a stab.

I need a macro that will view a group of cells i have selected and delete any rows that have an identical value in each selected cell in that row.

EG.

Mark, procured, processed, fabricated, welded, despatched
item(a), 1, 1, 1, 1, 1
item(b), 1, 1, 1, 1, 2
item(c), 1, 1, 1, 1, 1
item(d), 1, 2, 2, 1, 1

I i draged my cursor over the data in the procured, processed, fabricated, welded, despatched columns and ran the macro it would need to delete row with item(a) and item(c) because those values were identical in each cell.

I assume i would start the macro with:

For Each cell In Selection <-- as this would use the selected cells for the data to filter, but i dunno where to go from there.

Cheers guys,
Ant
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Type the following formula into G1 and copy down:
=SUMPRODUCT(--(B2:$B$9=B1),--(C2:$C$9=C1),--(D2:$D$9=D1),--(E2:$E$9=D1))

Then run this macro()

Sub Macro1()
Dim cell As Range
[g65536].End(xlUp).Select
Do Until ActiveCell.Row = 1
If ActiveCell.Value > 0 Then ActiveCell.EntireRow.Delete
ActiveCell.Offset(-1, 0).Select
Loop
If ActiveCell.Value > 0 Then ActiveCell.EntireRow.Delete
End Sub
 
Upvote 0
You could always incorporate the SUMPRODUCT() into the code, Anton :wink: EDIT: What was I thinkin'?

Nice solution, BTW
 
Upvote 0
INSTRUCTION:
(1) Select the area you wish to evaluate
(2) Run Maco called "DeleteDupes"

ASSUMPTIONS
- That column IV is blank and available for temp use.

Code:
Public Sub DeleteDupes()
    'MAKE A SINGLE STRING OF ROW
    Call MakeCombStr
    
    'FIND OUT IF COMBINED STRING IS UNIQUE
    Call ClearUniquesCombStr
    
    'DELETE ANY ROWS THAT ARE NOT UNIQUE
    On Error Resume Next
    Columns("IV:IV").SpecialCells(xlCellTypeConstants, 3).EntireRow.Delete

End Sub

Private Sub MakeCombStr()
For Each R In Selection.Rows
    TheStr = ""
    For Each c In R.Columns
        TheStr = TheStr & c.Value
    Next c
    Cells(R.Row, 256).Value = TheStr
Next R
End Sub

Private Sub ClearUniquesCombStr()
On Error GoTo TheEnd
For Each CombStr In Columns("IV:IV").SpecialCells(xlCellTypeConstants, 3)
    If WorksheetFunction.CountIf(Columns("IV:IV"), CombStr) < 2 Then
        CombStr.ClearContents
    End If
Next CombStr
TheEnd:
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,801
Messages
6,121,644
Members
449,045
Latest member
Marcus05

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