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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with a delete Function

Status
Not open for further replies.

Fiat77

Programmer
Feb 4, 2005
63
US
I need to modify this. I have a range of Row 2 to Row 371 always for this sheet. What I need to do is if there is not a value of 1 in Column D for Rows 2:371, I need the row to be deleted. How can I modify this?
Thanks

Sub DeleteLongQuoteRows()


Dim c As Range
'Application.ScreenUpdating = False
Do: Set c = Worksheets("Sheet1").[D:D]. _
Find("1", LookIn:=xlValues, lookAt:=xlPart)
If Not c Is Nothing Then _
c.EntireRow.Delete Else _
Exit Do

Loop
'Application.ScreenUpdating = True


End Sub
 
Fiat77,

There have been many examples of deleting rows programatically in this site.

Please do a search.

Note that the key element for deleting row by row is to delete from the bottom up.

But, why not try to auto filter and delete in one swell foop!

Skip,
[sub]
[glasses] [red]Be advised:[/red]When Viscounts were guillotined just as they were disclosing where their jewels were hidden, it shows to go that you should...
Never hatchet your Counts before they chicken! [tongue][/sub]
 
I personally try to avoid looping when possible. Try the following, it is much faster (and cleaner) than looping:
Code:
Sub deleterows()
Cells.AutoFilter Field:=4, Criteria1:="<>1"
Rows("2:65536").SpecialCells(xlCellTypeVisible).delete
Cells.AutoFilter
End Sub

[tt]_____
[blue]-John[/blue]
[/tt][red]"I'm against picketing, but I don't know how to show it."[/red]
-Mitch Hedberg

Help us help you. Please read FAQ181-2886 before posting.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top