PDA

View Full Version : Sleeper: Selecting rows in between 2 speicific words



everytime
08-07-2005, 08:29 AM
hi there , is there some way which i can select all the row inbetween 2 specific words ... say onshore , offshore , on and off shore ..

thanks in advance

Jacob Hilderbrand
08-07-2005, 10:29 AM
Try this:


Option Explicit

Sub SelectRange()
Dim FirstRow As Long
Dim LastRow As Long
On Error Resume Next
FirstRow = Cells.Find(What:="On Shore", After:=Range("IV65536"), LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext).Row
LastRow = Cells.Find(What:="Off Shore", After:=Range("A1"), LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
On Error GoTo 0
If FirstRow > 0 And LastRow > 0 Then
Range("A" & FirstRow + 1 & ":IV" & LastRow - 1).Select
End If
End Sub