Thread: Delete Rows
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
JohnUK JohnUK is offline
external usenet poster
 
Posts: 173
Default Delete Rows

Hi Norman,
Thanks for your help.
I ran your code and instead of deleting the rows with the name I entered
into the range, it deleted the range instead.
Did I do something wrong
John


"Norman Jones" wrote:

Hi John,

Try:

'================
Public Sub TesterX()
Dim WB As Workbook
Dim SH As Worksheet
Dim rng As Range
Dim rCell As Range
Dim delRng As Range
Dim CalcMode As Long
Const SearchCol As String = "G" '<<===== CHANGE

Set WB = Workbooks("YourBook.xls") '<<===== CHANGE
Set SH = WB.Sheets("Sheet4") '<<===== CHANGE

With SH
Set rng = Intersect(.Range("Names"), .Columns(SearchCol))
End With

If rng Is Nothing Then Exit Sub

On Error GoTo XIT
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

For Each rCell In rng.Cells
If UCase(rCell.Value) = "FRED" Then
If delRng Is Nothing Then
Set delRng = rCell
Else
Set delRng = Union(rCell, delRng)
End If
End If
Next rCell

If Not delRng Is Nothing Then
delRng.EntireRow.Delete
End If

XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub
'<<================


---
Regards,
Norman


"JohnUK" wrote in message
...
Hi Again,
Can anyone help with this one?
Is there a way that Row/s can be deleted depending on names in a range?
For example:
If a range (called NAMES) had FRED in it and rows 10,20,30 had the name
FRED
in column G, all those rows would be deleted.
My poor attempt:

Row = Range("NAMES").Text
Rows(Range("NAMES").Text).Delete

Again many thanks for help
John