Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 19
Default if function to delete row

hi,
may i know how to write this?

if column X or column y or column z is 0 then i need to delete this row.

thanks

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default if function to delete row

Right click you sheet tab, view code and paste this in and run it

Sub marine()
Dim myrange, copyrange As Range
Lastrow = Cells(Cells.Rows.Count, "X").End(xlUp).Row
Set myrange = Range("X1:X" & Lastrow)
For Each c In myrange
If Not IsEmpty(c) And c.Value = 0 And _
Not IsEmpty(c.Offset(, 1)) And c.Offset(, 1).Value = 0 And _
Not IsEmpty(c.Offset(, 2)) And c.Offset(, 2).Value = 0 Then
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If
End Sub

Mike

"AskExcel" wrote:

hi,
may i know how to write this?

if column X or column y or column z is 0 then i need to delete this row.

thanks

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 19
Default if function to delete row

Hi,
thanks but i do not understand your code.
may i know if there is any simpler way?
thanks


"Mike H" wrote:

Right click you sheet tab, view code and paste this in and run it

Sub marine()
Dim myrange, copyrange As Range
Lastrow = Cells(Cells.Rows.Count, "X").End(xlUp).Row
Set myrange = Range("X1:X" & Lastrow)
For Each c In myrange
If Not IsEmpty(c) And c.Value = 0 And _
Not IsEmpty(c.Offset(, 1)) And c.Offset(, 1).Value = 0 And _
Not IsEmpty(c.Offset(, 2)) And c.Offset(, 2).Value = 0 Then
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If
End Sub

Mike

"AskExcel" wrote:

hi,
may i know how to write this?

if column X or column y or column z is 0 then i need to delete this row.

thanks

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default if function to delete row

Hi,

What you can't do is have an IF formula along the lines of

=If(x2=0,delete the row, don't delete the row)
so if you want to delete rows without code then it's a manual process. You
could set up an autofilter to only display the rows that meet your criteria
and then delete the visible rows but why not try the code it's simple

Right click you sheet tab, view code and paste it in and run it by tapping F5

Mike


"AskExcel" wrote:

Hi,
thanks but i do not understand your code.
may i know if there is any simpler way?
thanks


"Mike H" wrote:

Right click you sheet tab, view code and paste this in and run it

Sub marine()
Dim myrange, copyrange As Range
Lastrow = Cells(Cells.Rows.Count, "X").End(xlUp).Row
Set myrange = Range("X1:X" & Lastrow)
For Each c In myrange
If Not IsEmpty(c) And c.Value = 0 And _
Not IsEmpty(c.Offset(, 1)) And c.Offset(, 1).Value = 0 And _
Not IsEmpty(c.Offset(, 2)) And c.Offset(, 2).Value = 0 Then
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If
End Sub

Mike

"AskExcel" wrote:

hi,
may i know how to write this?

if column X or column y or column z is 0 then i need to delete this row.

thanks

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,388
Default if function to delete row

Hi AE,

As far as I am aware, a formula can only give you a result, not an action.
So a formula cannot delete rows; you have to use a macro.
Regards - Dave.
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
Using a function to delete blank cells Carter Devereaux Excel Worksheet Functions 2 September 1st 07 03:40 PM
How do I delete a column that has been used for a function? DorianG Excel Worksheet Functions 1 January 5th 07 02:09 PM
Delete Cell Function roy.okinawa Excel Worksheet Functions 7 November 23rd 05 05:49 AM
How do I protect cells against only the "Delete" function? Kev Nurse Excel Discussion (Misc queries) 1 February 17th 05 03:09 AM
How do I protect work sheet against the "Delete" function? Kev Nurse Excel Discussion (Misc queries) 1 February 17th 05 03:01 AM


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