#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 70
Default Delete entire row if

I'm trying create a macros that will delete the entire row if the values in
cells T26 , U26, V26, and W26 are all 0. My macro is deleting all the rows
even if the values of the cells are not 0. Can anyone tweak my code ?

Dim lastrow As Long
Dim r As Long
lastrow = Range("T" & Rows.Count).End(xlUp).Row
For r = lastrow To 2 Step -1
If (InStr(1, Cells(r, 20).Value) And (InStr(1, Cells(r, 21).Value) And _
InStr(1, Cells(r, 23).Value) And InStr(1, Cells(r, 24).Value))) = 0
Then



ActiveSheet.Rows(r).EntireRow.Delete
End If

Next
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,726
Default Delete entire row if

Dim lastrow As Long
Dim r As Long
lastrow = Range("T" & Rows.Count).End(xlUp).Row
For r = lastrow To 2 Step -1
If Application.Countif(Cells(r,"T").Resize(1,4),0) = 4 Then
ActiveSheet.Rows(r).Delete
End If
Next
End Sub


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)
"David T" wrote in message
...
I'm trying create a macros that will delete the entire row if the values
in
cells T26 , U26, V26, and W26 are all 0. My macro is deleting all the
rows
even if the values of the cells are not 0. Can anyone tweak my code ?

Dim lastrow As Long
Dim r As Long
lastrow = Range("T" & Rows.Count).End(xlUp).Row
For r = lastrow To 2 Step -1
If (InStr(1, Cells(r, 20).Value) And (InStr(1, Cells(r, 21).Value) And
_
InStr(1, Cells(r, 23).Value) And InStr(1, Cells(r, 24).Value))) =
0
Then



ActiveSheet.Rows(r).EntireRow.Delete
End If

Next
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Delete entire row if

may be:

Sub david()
Dim lastrow As Long
Dim r As Long
lastrow = Range("T" & Rows.Count).End(xlUp).Row
For r = lastrow To 2 Step -1
v1 = Cells(r, "T").Value
v2 = Cells(r, "U").Value
v3 = Cells(r, "V").Value
v4 = Cells(r, "W").Value
If v1 = 0 And v2 = 0 And v3 = 0 And v4 = 0 Then
Cells(r, "A").EntireRow.Delete
End If
Next
End Sub
--
Gary's Student


"David T" wrote:

I'm trying create a macros that will delete the entire row if the values in
cells T26 , U26, V26, and W26 are all 0. My macro is deleting all the rows
even if the values of the cells are not 0. Can anyone tweak my code ?

Dim lastrow As Long
Dim r As Long
lastrow = Range("T" & Rows.Count).End(xlUp).Row
For r = lastrow To 2 Step -1
If (InStr(1, Cells(r, 20).Value) And (InStr(1, Cells(r, 21).Value) And _
InStr(1, Cells(r, 23).Value) And InStr(1, Cells(r, 24).Value))) = 0
Then



ActiveSheet.Rows(r).EntireRow.Delete
End If

Next
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I delete an entire row if condition is not met? Christine Excel Worksheet Functions 8 May 4th 06 09:47 AM
Easiest way to delete blank cells in column (not entire row) sramsey Excel Discussion (Misc queries) 4 February 16th 06 04:28 PM
How to delete rows when List toolbar's "delete" isnt highlighted? Linda Excel Worksheet Functions 1 May 26th 05 08:39 PM
can I delete entire row if adjacent cell formats differ? ksukid Excel Worksheet Functions 0 May 19th 05 09:28 PM
How to delete blank rows John Mansfield Excel Discussion (Misc queries) 3 April 27th 05 11:48 PM


All times are GMT +1. The time now is 08:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"