First occurance of text in a column
Sub totals()
rrow = ActiveCell.Row
s = "Totals"
mesage = ""
For i = rrow To 1 Step -1
If Cells(i, "A").Value = s Then
mesage = Cells(i, "A").Row
Exit For
End If
Next
For i = rrow To Rows.Count
If Cells(i, "A").Value = s Then
mesage = mesage & Chr(10) & Cells(i, "A").Row
Exit For
End If
Next
MsgBox (mesage)
End Sub
--
Gary''s Student - gsnu2007L
"John" wrote:
Column A has the text "Totals" in several random cells. In VBA I would like
2 variables that return the row numbers of the first occurances of "Totals"
in Column A of the rows above and below the active cell, regardless of where
the active cell is. Thank you.
|