Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Delete row when zero

Hi
Can some one help me with macro or vba code to delete the row when column B,,C,D, and E all 4 have the value of 0
(It has to be 0 in all 4 column). Its very big sheet with thousands of rows. Please help

Thank
Andy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Delete row when zero

Hi Sorry All, Forget to tell you I dont want this code to look row 1 thru 6. Should start from row 7 and end at row till the data ends
Can some one help me with macro or vba code to delete the row when column B,,C,D, and E all 4 have the value of 0
(It has to be 0 in all 4 column). Its very big sheet with thousands of rows. Please help

Thank
And

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Delete row when zero

Hi Andy,

Try:

Sub Tester()
Dim i As Long
Dim LRow As Long
Dim sh As Worksheet

' Change the sheet name to your sheet name!
Set sh = ActiveWorkbook.Sheets("Sheet1")

LRow = LastRow(sh)

For i = LRow To 7 Step -1

With sh
If Application.Max(.Cells(i, 2).Resize(1, 4)) = 0 And _
Application.Min(.Cells(i, 2).Resize(1, 4)) = 0 Then
.Cells(i, 2).EntireRow.Delete
End If
End With
Next i

End Sub

Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
after:=sh.Range("A1"), _
lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function


---
Regards,
Norman

"Andy" wrote in message
...
Hi Sorry All, Forget to tell you I dont want this code to look row 1 thru

6. Should start from row 7 and end at row till the data ends.
Can some one help me with macro or vba code to delete the row when column

B,,C,D, and E all 4 have the value of 0.
(It has to be 0 in all 4 column). Its very big sheet with thousands of

rows. Please help

Thanks
Andy



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Delete row when zero

Hi Andy,

Try:
Sub Tester()
Dim i As Long
Dim LRow As Long
Dim sh As Worksheet

' Change the sheet name to your sheet name!
Set sh = ActiveWorkbook.Sheets("Sheet1")

LRow = LastRow(sh)

For i = LRow To 7 Step -1

With sh
If Application.Max(.Cells(i, 2).Resize(1, 4)) = 0 And _
Application.Min(.Cells(i, 2).Resize(1, 4)) = 0 Then
.Cells(i, 2).EntireRow.Delete
End If
End With
Next i

End Sub

Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
after:=sh.Range("A1"), _
lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function


---
Regards,
Norman

"Andy" wrote in message
...
Hi Sorry All, Forget to tell you I dont want this code to look row 1 thru

6. Should start from row 7 and end at row till the data ends.
Can some one help me with macro or vba code to delete the row when column

B,,C,D, and E all 4 have the value of 0.
(It has to be 0 in all 4 column). Its very big sheet with thousands of

rows. Please help

Thanks
Andy



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Delete row when zero

This

If Application.Max(.Cells(i, 2).Resize(1, 4)) = 0 And _
Application.Min(.Cells(i, 2).Resize(1, 4)) = 0 Then

can be reduced to

If Application.Countif(.Cells(i, 2).Resize(1, 4)),0) = 4 Then


--

HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Norman Jones" wrote in message
...
Hi Andy,

Try:
Sub Tester()
Dim i As Long
Dim LRow As Long
Dim sh As Worksheet

' Change the sheet name to your sheet name!
Set sh = ActiveWorkbook.Sheets("Sheet1")

LRow = LastRow(sh)

For i = LRow To 7 Step -1

With sh
If Application.Max(.Cells(i, 2).Resize(1, 4)) = 0 And _
Application.Min(.Cells(i, 2).Resize(1, 4)) = 0 Then
.Cells(i, 2).EntireRow.Delete
End If
End With
Next i

End Sub

Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
after:=sh.Range("A1"), _
lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function


---
Regards,
Norman

"Andy" wrote in message
...
Hi Sorry All, Forget to tell you I dont want this code to look row 1

thru
6. Should start from row 7 and end at row till the data ends.
Can some one help me with macro or vba code to delete the row when

column
B,,C,D, and E all 4 have the value of 0.
(It has to be 0 in all 4 column). Its very big sheet with thousands of

rows. Please help

Thanks
Andy







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete row when zero

Hi
Why dont you use the Data--Filter--Autofilter option to filter out zeroes in all the 4 columns, and delete all rows which match the criteria?
Sukhjeet
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
delete the test values, but do not delete the formulas kathy Excel Discussion (Misc queries) 1 February 21st 07 07:03 PM
How can I delete a macro when the Delete button is not active? FCR Excel Worksheet Functions 0 March 9th 06 09:43 AM
How to Delete a Range in Closed Workbook (to Replace Delete Query) [email protected] Excel Discussion (Misc queries) 1 March 8th 06 10:10 AM
How do i delete a macro in Excel 2003 when delete isn't highlight Abel Excel Discussion (Misc queries) 2 September 13th 05 04:09 AM
How to delete rows when List toolbar's "delete" isnt highlighted? Linda Excel Worksheet Functions 1 May 26th 05 08:39 PM


All times are GMT +1. The time now is 12:08 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"