Macro

N

Neil

How do I find a value (or values) in a range (column) and delte it /them when
found

All suggestions appreciated
 
J

Joel

Data = 345
Set found = Columns("A").Find(what:=Data, LookIn:=xlValues, lookat:=xlWhole)
If Not found Is Nothing Then
found.Delete shift:=xlShiftUp
End If
 
D

Don Guillett

Sub findanddelete()
mc = "a"
For i = Cells(rows.Count, mc).End(xlUp).Row To 1 Step -1
If Cells(i, mc) = 3 Then rows(i).Delete
Next i
End Sub
 
R

ryguy7272

Not as eloquent as some others, but this should get the job done:

Sub DeleteDuplicateRows()
'
' This macro deletes duplicate rows in the selection. Duplicates are
' counted in the COLUMN of the active cell.

Dim Col As Integer
Dim r As Long
Dim C As Range
Dim n As Long
Dim v As Variant
Dim rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Col = ActiveCell.Column

If Selection.Rows.count > 1 Then
Set rng = Selection
Else
Set rng = ActiveSheet.UsedRange.Rows
End If

n = 0
For r = rng.Rows.count To 1 Step -1
v = rng.Cells(r, 1).Value
If Application.WorksheetFunction.CountIf(rng.Columns(1), v) > 1 Then
rng.Rows(r).EntireRow.Delete
n = n + 1
End If
Next r

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub

Regards,
Ryan---
 
N

Neil

great thanks for the quick response
--
Neil


ryguy7272 said:
Not as eloquent as some others, but this should get the job done:

Sub DeleteDuplicateRows()
'
' This macro deletes duplicate rows in the selection. Duplicates are
' counted in the COLUMN of the active cell.

Dim Col As Integer
Dim r As Long
Dim C As Range
Dim n As Long
Dim v As Variant
Dim rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Col = ActiveCell.Column

If Selection.Rows.count > 1 Then
Set rng = Selection
Else
Set rng = ActiveSheet.UsedRange.Rows
End If

n = 0
For r = rng.Rows.count To 1 Step -1
v = rng.Cells(r, 1).Value
If Application.WorksheetFunction.CountIf(rng.Columns(1), v) > 1 Then
rng.Rows(r).EntireRow.Delete
n = n + 1
End If
Next r

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub

Regards,
Ryan---
 
N

Neil

thanks for the quick reply Don
--
Neil


Don Guillett said:
Sub findanddelete()
mc = "a"
For i = Cells(rows.Count, mc).End(xlUp).Row To 1 Step -1
If Cells(i, mc) = 3 Then rows(i).Delete
Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
 
N

Neil

Great thanks for the quick reply Joel
--
Neil


Joel said:
Data = 345
Set found = Columns("A").Find(what:=Data, LookIn:=xlValues, lookat:=xlWhole)
If Not found Is Nothing Then
found.Delete shift:=xlShiftUp
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top