Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Deleting Rows

Hello, I need to create a macro to delete an entire row if a cell
value in a selected cell of that row has a zero value. Any
suggestions?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Deleting Rows

Try something like

Sub AAA()
If IsEmpty(ActiveCell.Value) = False Then
If IsNumeric(ActiveCell.Value) = True Then
If ActiveCell.Value = 0 Then
ActiveCell.EntireRow.Delete xlShiftUp
End If
End If
End If
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"amanda" wrote in message
ups.com...
Hello, I need to create a macro to delete an entire row if a cell
value in a selected cell of that row has a zero value. Any
suggestions?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default Deleting Rows

Try searching this NG. But if you're too lazy to do that start with this:
Sub DeleteRows()
Const StartRow As Long = 1 'Row to Start looking at
Const StopRow As Long = 65000 'Row to Stop looking at
Const Col As Long = 2 'Column to search for 0 in
Dim cnt As Long
For cnt = StopRow to StartRow Step -1
If Cells(cnt,Col) = 0 Then Rows(cnt).Delete
Next
End Sub
--
Charles Chickering

"A good example is twice the value of good advice."


"amanda" wrote:

Hello, I need to create a macro to delete an entire row if a cell
value in a selected cell of that row has a zero value. Any
suggestions?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 903
Default Deleting Rows

Hi Charles,
I would give the macro a much more descriptive name
of what rows are being deleted. Simply going through
65000 rows is not going to be efficient, nor is it correct.
While your version may have 65536 rows that restriction
will be upped considerably in Excel 2007, and I presume
nobody is still using Excel 95. But going through 65536
cell comparisons on my computer would take a few minutes,
if you have only 300 rows, it should go extremely fast even
on my computer when it had 128MB RAM.

col = activecell.column
StopRow = Cells(Rows.Count, col).End(xlUp)).Row

Changed it from Column B to the column of the activecell
to make the macro more generic.

Sub Del_rows_with_zero_in_column_of_activecell()
Const StartRow As Long = 1 'Row to Start looking at
Dim StopRow As Long
Dim Col As Long
Col = ActiveCell.Column
StopRow = Cells(Rows.Count, Col).End(xlUp).Row
Dim cnt As Long
For cnt = StopRow To StartRow Step -1
If IsNumeric(Cells(cnt, Col)) Then
If Cells(cnt, Col) = 0 Then Rows(cnt).Delete
End If
Next
End Sub

Additional references: (the first is on Slow Response)
http://www.mvps.org/dmcritchie/excel/slowresponse.htm
http://www.mvps.org/dmcritchie/excel/delempty.htm
http://www.mvps.org/dmcritchie/excel/toolbars.htm

---
HTH,
David McRitchie, Microsoft MVP - Excel
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm

"Charles Chickering" wrote in message
...
Try searching this NG. But if you're too lazy to do that start with this:
Sub DeleteRows()
Const StartRow As Long = 1 'Row to Start looking at
Const StopRow As Long = 65000 'Row to Stop looking at
Const Col As Long = 2 'Column to search for 0 in
Dim cnt As Long
For cnt = StopRow to StartRow Step -1
If Cells(cnt,Col) = 0 Then Rows(cnt).Delete
Next
End Sub
--
Charles Chickering

"A good example is twice the value of good advice."


"amanda" wrote:

Hello, I need to create a macro to delete an entire row if a cell
value in a selected cell of that row has a zero value. Any
suggestions?




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 903
Default Deleting Rows

correction must check the cell that it is not empty as well
like Chip indicated in his reply.

Sub Del_rows_with_zero_in_column_of_activecell()
Const StartRow As Long = 1 'Row to Start looking at
Dim StopRow As Long
Dim Col As Long
Col = ActiveCell.Column
StopRow = Cells(Rows.Count, Col).End(xlUp).Row
Dim cnt As Long
For cnt = StopRow To StartRow Step -1
If Not IsEmpty(Cells(cnt, Col)) Then
If IsNumeric(Cells(cnt, Col)) Then
If Cells(cnt, Col) = 0 Then Rows(cnt).Delete
End If
End If
Next cnt
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
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Links and Linking in Excel 1 November 13th 08 08:44 AM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Setting up and Configuration of Excel 1 November 12th 08 06:05 PM
Macro for deleting rows and serialising the remaing rows Srinivasulu Bhattaram Excel Worksheet Functions 1 November 12th 08 01:39 PM
Help!! I have problem deleting 2500 rows of filtered rows!!!! shirley_kee Excel Discussion (Misc queries) 1 January 12th 06 03:24 AM
Help!!! I have problem deleting 2500 rows of filtered rows shirley_kee[_2_] Excel Programming 1 January 12th 06 03:15 AM


All times are GMT +1. The time now is 02:15 AM.

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"