Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Rows in excel when criteria met. 2

Status
Not open for further replies.

jupops

Technical User
May 15, 2003
72
GB
Good Evening

Can anybody help?

I am trying to write a quick macro that will see a first word in column A (Selection) which if met will delete that row and next 3 rows beneath it. Then carry on looking down the spreadsheet to repeat if necessary

The code I have tried and failed with is:

Sub DelRow()
rng = Selection.Rows.Count
ActiveCell.Offset(0, 0).Select
Application.ScreenUpdating = False
For i = 1 To rng
If ActiveCell.Value = "Selection" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
Next i
Application.ScreenUpdating = True
End Sub


I will be grateful for any help

Regards
Jupops.
 

hi,
Code:
Sub DelRow()
    Dim r As Range
    
    Application.ScreenUpdating = False
    
    Set r = Columns(1).Find("Selection")
    
    Do While Not r Is Nothing
        Range(r, r.Offset(3)).EntireRow.Delete
        Set r = Columns(1).Find("Selection")
    Loop
    
    Application.ScreenUpdating = True
End Sub

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Thank you

Spot on again, You are a star

Jupops
 
Skip,
Is there anyway I could put you in a carry all and bring you to NZ . . . you are awesome, thanks so much for this post

Merry Part and the Brightest of Blessings

With respect
Wicca
-----
IF you think you can
Or
If you think you can't
Then
You are probably right
-Henry Ford
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top