LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete rows based on results of cell tests

Hi

I have ~200 rows of data - this data is split into groups of 5-12
rows.
At the bottom of each of these groups is a total

I am trying to find the rows with the word "total" and test if the
value one cell to the right=0
if the total=0 then i want to delete all the rows between this total
and the next total which does not equal 0

I fairly amateurish with my VBA but below is what I have so far
(probably completely wrong)
A sample of what the data might look is at the bottom

Thanks for your help
Iain


Sub ZeroChunkDelete

Dim lastrow As Long
Dim n As Long
Dim m As Long
Dim BottomZeroTotal As Long
Dim TopZeroTotal As Long

lastrow = Sheets("Print Out").Cells(Cells.Rows.Count, "B").End
(xlDown).Row
For n = lastrow To 1 Step -1
If UCase(Cells(n, 1).Value) = "Total" And Selection.End
(xlToRight).Value = 0 Then BottomZeroTotal = n
Next n

For m = n To 1 Step -1
If UCase(Cells(m, 1).Value) = "Total" And Selection.End
(xlToRight).Value = 0 Then TopZeroTotal = m
Next m
Worksheets("Print Out").Rows(TopZeroTotal & ":" &
BottomZeroTotal).Delete
End Sub


Data sample
A B
2
0
1
total 3
}
0 }
0 }I want to delete these rows
0 }
total 0 }

1
0
total 1



 
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
Delete Rows based on cell value [email protected] Excel Programming 7 January 18th 08 04:29 AM
Delete Rows based on cell values. Little Penny[_2_] Excel Programming 2 September 25th 07 02:23 PM
Delete duplicate rows based on part of cell. okrob Excel Programming 0 February 14th 07 07:25 PM
Delete rows based on Cell name gmunro Excel Programming 1 November 25th 05 01:09 PM


All times are GMT +1. The time now is 08:17 AM.

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"