Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default deleting selected rows

I've got a workbook filled with worksheets containing 4 columns of
data each. I'd like to delete all of the rows (in each worksheet)
whose column B, C, and D cells contain the value "0". I am guessing
this is something that can be accomplished with nested loops, but I am
terribly rusty at VB. Can I get a push in the right direction?

Thanks much.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default deleting selected rows

Enter and run this small macro:

Sub delete_some_rows()

Dim r As Range, j As Long

Set r = ActiveSheet.UsedRange
j = r.Rows.Count + r.Row
Set rdel = Cells(j, "A")
For i = 1 To j - 1
v1 = Cells(i, "B").Value
v2 = Cells(i, "C").Value
v3 = Cells(i, "D").Value
If v1 = 0 And v2 = 0 And v3 = 0 Then
Set rdel = Union(rdel, Cells(i, "A"))
End If
Next

rdel.EntireRow.Delete

End Sub

--
Gary's Student


"Worker Bee" wrote:

I've got a workbook filled with worksheets containing 4 columns of
data each. I'd like to delete all of the rows (in each worksheet)
whose column B, C, and D cells contain the value "0". I am guessing
this is something that can be accomplished with nested loops, but I am
terribly rusty at VB. Can I get a push in the right direction?

Thanks much.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 422
Default deleting selected rows

The easiest way - use the Data -Auto-filter feature
Select using the "0" and Delete all visible rows;
Might take several steps, but "it's easy".

"Worker Bee" wrote in message
:

I've got a workbook filled with worksheets containing 4 columns of
data each. I'd like to delete all of the rows (in each worksheet)
whose column B, C, and D cells contain the value "0". I am guessing
this is something that can be accomplished with nested loops, but I am
terribly rusty at VB. Can I get a push in the right direction?

Thanks much.


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 340
Default deleting selected rows

With the columns selected choose Edit Find: 0 and click Find All then
press Ctrl+A to select all cells and Entire Row Delete.


Worker Bee wrote:

I've got a workbook filled with worksheets containing 4 columns of
data each. I'd like to delete all of the rows (in each worksheet)
whose column B, C, and D cells contain the value "0". I am guessing
this is something that can be accomplished with nested loops, but I am
terribly rusty at VB. Can I get a push in the right direction?

Thanks much.


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default deleting selected rows

Both Gary's and JMay suggestion were great. But I will prefer JMay because
Macros can not be undo. Am I right Gary?



"Gary''s Student" wrote:

Enter and run this small macro:

Sub delete_some_rows()

Dim r As Range, j As Long

Set r = ActiveSheet.UsedRange
j = r.Rows.Count + r.Row
Set rdel = Cells(j, "A")
For i = 1 To j - 1
v1 = Cells(i, "B").Value
v2 = Cells(i, "C").Value
v3 = Cells(i, "D").Value
If v1 = 0 And v2 = 0 And v3 = 0 Then
Set rdel = Union(rdel, Cells(i, "A"))
End If
Next

rdel.EntireRow.Delete

End Sub

--
Gary's Student


"Worker Bee" wrote:

I've got a workbook filled with worksheets containing 4 columns of
data each. I'd like to delete all of the rows (in each worksheet)
whose column B, C, and D cells contain the value "0". I am guessing
this is something that can be accomplished with nested loops, but I am
terribly rusty at VB. Can I get a push in the right direction?

Thanks much.



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default deleting selected rows

You are absolutely correct. Because AutoFilter only hides rows instead of
deleting them, you can un-do with only the click of the mouse.

The other great advantage of AutoFilter is, that by inserting a helper
column, you can hide rows based upon any criteria you choose.
--
Gary's Student


"RajKohli" wrote:

Both Gary's and JMay suggestion were great. But I will prefer JMay because
Macros can not be undo. Am I right Gary?



"Gary''s Student" wrote:

Enter and run this small macro:

Sub delete_some_rows()

Dim r As Range, j As Long

Set r = ActiveSheet.UsedRange
j = r.Rows.Count + r.Row
Set rdel = Cells(j, "A")
For i = 1 To j - 1
v1 = Cells(i, "B").Value
v2 = Cells(i, "C").Value
v3 = Cells(i, "D").Value
If v1 = 0 And v2 = 0 And v3 = 0 Then
Set rdel = Union(rdel, Cells(i, "A"))
End If
Next

rdel.EntireRow.Delete

End Sub

--
Gary's Student


"Worker Bee" wrote:

I've got a workbook filled with worksheets containing 4 columns of
data each. I'd like to delete all of the rows (in each worksheet)
whose column B, C, and D cells contain the value "0". I am guessing
this is something that can be accomplished with nested loops, but I am
terribly rusty at VB. Can I get a push in the right direction?

Thanks much.

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
Deleting empty rows (special case) Ali Excel Discussion (Misc queries) 1 June 12th 06 07:57 PM
Deleting Blank Rows Reeni New Users to Excel 4 December 15th 05 01:56 AM
Deleting All Rows for Duplicate Entries Except Those With Most Items In Row foofoo Excel Discussion (Misc queries) 1 October 22nd 05 02:49 AM
Insert rows Mr. G. Excel Worksheet Functions 3 March 31st 05 03:49 AM
Deleting rows containing common data gcotterl Excel Discussion (Misc queries) 1 January 4th 05 12:58 AM


All times are GMT +1. The time now is 11:00 PM.

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

About Us

"It's about Microsoft Excel"