Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Can I conditionally delete row in Excel? (if B3=0 delete row B)

I am trying to delete rows based on conditional statements. For example,
delete row B if cell B3(budget balance) is 0. I am having trouble figuring
this out. Can I incorporate a macro that deletes a row into an "if"
statement? Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Can I conditionally delete row in Excel? (if B3=0 delete row B)

Do you need a macro or can you do it manually?

If manually is ok:

I'd use another column of Cells:

=if(b2=0,"deleteme","keepme")
and drag down.

Then apply data|filter|autofilter to that helper column. And show the Deleteme
rows.

And delete those visible rows.

Remove the filter and delete that helper column.

Badger wrote:

I am trying to delete rows based on conditional statements. For example,
delete row B if cell B3(budget balance) is 0. I am having trouble figuring
this out. Can I incorporate a macro that deletes a row into an "if"
statement? Thanks.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Can I conditionally delete row in Excel? (if B3=0 delete row B

Thanks. I need it to be automated so I think a macro is my only choice
unless I can somehow incorporate a conditional delete row function into a
cell formula.

"Dave Peterson" wrote:

Do you need a macro or can you do it manually?

If manually is ok:

I'd use another column of Cells:

=if(b2=0,"deleteme","keepme")
and drag down.

Then apply data|filter|autofilter to that helper column. And show the Deleteme
rows.

And delete those visible rows.

Remove the filter and delete that helper column.

Badger wrote:

I am trying to delete rows based on conditional statements. For example,
delete row B if cell B3(budget balance) is 0. I am having trouble figuring
this out. Can I incorporate a macro that deletes a row into an "if"
statement? Thanks.


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Can I conditionally delete row in Excel? (if B3=0 delete row B

Maybe something like:

Option Explicit
Sub testme()

Dim rng As Range
Dim wks As Worksheet
Dim myCell As Range
Dim DelRng As Range

Set wks = Worksheets("Sheet1")

With wks
Set rng = .Range("B2", .Cells(.Rows.Count, "B").End(xlUp))
End With

For Each myCell In rng.Cells
If IsEmpty(myCell) = False Then
If myCell.Value = 0 Then
If DelRng Is Nothing Then
Set DelRng = myCell
Else
Set DelRng = Union(myCell, DelRng)
End If
End If
End If
Next myCell

If DelRng Is Nothing Then
'do nothing
Else
DelRng.Select
'or (after testing!)
'DelRng.EntireRow.Delete
End If

End Sub

Badger wrote:

Thanks. I need it to be automated so I think a macro is my only choice
unless I can somehow incorporate a conditional delete row function into a
cell formula.

"Dave Peterson" wrote:

Do you need a macro or can you do it manually?

If manually is ok:

I'd use another column of Cells:

=if(b2=0,"deleteme","keepme")
and drag down.

Then apply data|filter|autofilter to that helper column. And show the Deleteme
rows.

And delete those visible rows.

Remove the filter and delete that helper column.

Badger wrote:

I am trying to delete rows based on conditional statements. For example,
delete row B if cell B3(budget balance) is 0. I am having trouble figuring
this out. Can I incorporate a macro that deletes a row into an "if"
statement? Thanks.


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Can I conditionally delete row in Excel? (if B3=0 delete row B

Thank you so much!

"Dave Peterson" wrote:

Maybe something like:

Option Explicit
Sub testme()

Dim rng As Range
Dim wks As Worksheet
Dim myCell As Range
Dim DelRng As Range

Set wks = Worksheets("Sheet1")

With wks
Set rng = .Range("B2", .Cells(.Rows.Count, "B").End(xlUp))
End With

For Each myCell In rng.Cells
If IsEmpty(myCell) = False Then
If myCell.Value = 0 Then
If DelRng Is Nothing Then
Set DelRng = myCell
Else
Set DelRng = Union(myCell, DelRng)
End If
End If
End If
Next myCell

If DelRng Is Nothing Then
'do nothing
Else
DelRng.Select
'or (after testing!)
'DelRng.EntireRow.Delete
End If

End Sub

Badger wrote:

Thanks. I need it to be automated so I think a macro is my only choice
unless I can somehow incorporate a conditional delete row function into a
cell formula.

"Dave Peterson" wrote:

Do you need a macro or can you do it manually?

If manually is ok:

I'd use another column of Cells:

=if(b2=0,"deleteme","keepme")
and drag down.

Then apply data|filter|autofilter to that helper column. And show the Deleteme
rows.

And delete those visible rows.

Remove the filter and delete that helper column.

Badger wrote:

I am trying to delete rows based on conditional statements. For example,
delete row B if cell B3(budget balance) is 0. I am having trouble figuring
this out. Can I incorporate a macro that deletes a row into an "if"
statement? Thanks.

--

Dave Peterson


--

Dave Peterson

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
How do I conditionally delete rows based on cell contents? John Chan Excel Worksheet Functions 3 May 17th 23 03:45 AM
Conditionally delete James[_4_] Excel Discussion (Misc queries) 2 November 6th 07 05:55 PM
Conditionally Delete Cells From Named Range [email protected] Excel Programming 2 September 27th 04 06:21 PM
Delete every 3rd row, then delete rows 2-7, move info f/every 2nd row up one to the end and delete the row below Annette[_4_] Excel Programming 2 September 21st 04 02:40 PM
conditionally delete some elements from an array clui[_8_] Excel Programming 1 December 4th 03 01:21 AM


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