View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Earl Kiosterud Earl Kiosterud is offline
external usenet poster
 
Posts: 611
Default selecting rows of data

Mimmo,

Here's a non-code way. In a helper column (adjacent to the table, not
separated by any empty columns) put this formula (this one's for row 2):

=IF(AND(A2="Location",A3="Depth"),1,IF(AND(A2="Dep th",A1="Location"),1,0))

Now use AutoFilter on the helper column, filtering for 0. Select the
filtered rows (drag through the row headings at left). Delete the rows
(Ctrl -). Now set the Autofilter back to All. The helper column will have
some ref errors, but you don't need it any more. Delete it by selecting it
(click in the column header at top), and press Ctrl minus.

If you want a macro:

Sub RemoveRows()
Dim TestCell As Range
Set TestCell = Range("A2")
Do
If Not (LCase(TestCell) = "location" And LCase(TestCell.Offset(1, 0)) =
"depth") Then
Set TestCell = TestCell.Offset(1, 0)
TestCell.Offset(-1, 0).EntireRow.Delete
Set TestCell = TestCell.Offset(2, 0)

Else
Set TestCell = TestCell.Offset(2, 0)
End If
Loop While TestCell < ""
End Sub

--
Earl Kiosterud
www.smokeylake.com

"mimmo" wrote in
message ...

Hi: we just started using a new system where we capture location and
depth data from a sounder, for making depth maps of lakes.
Basically the data streams continuously into a text file which we can
easily import into Excel, but we have to select certain rows first.
Each row of data has an identifier in the first column that tells us if
it's depth or location data. The problem is that there is more location
data then there is depth, so here's what we need to do:

every time a row with location data is followed by a row of depth data,
then we want to keep both of those rows

every other combination that is different from above, delete the rows

so for example, if these were the rows (row number shown):

1 location
2 location
3 location
4 depth
5 location
6 location
7 depth

then the rows we want to keep are 3,4,6 and 7

sorry for the lengthy post, this is my first, I just thought it's a
unique problem and hopefully some of you will find it interesting and
provide a solution

thanks


--
mimmo
------------------------------------------------------------------------
mimmo's Profile:
http://www.excelforum.com/member.php...o&userid=26724
View this thread: http://www.excelforum.com/showthread...hreadid=399784