Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find help 1

Status
Not open for further replies.

Johnny42

Technical User
Jul 13, 2004
127
CA
Why am I getting this error :
error 91 Block With.....
With this code:
startRow = Worksheets("Sheet1").Columns("A").Find("100", _
LookIn:=xlValues, LookAt:=xlWhole).Row
 
You need to show more of your code - the error is in a WITH construct

Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 
Sub FindDates()
On Error GoTo errorHandler
Dim startDate As String
Dim stopDate As String
Dim startRow As Integer
Dim stopRow As Integer

startDate = 151515
startRow = Worksheets("ATELIER").Columns("A").Find(startDate, _
LookIn:=xlValues, lookat:=xlWhole).Row

MsgBox startRow
End
errorHandler:
MsgBox "There has been an error: " & Error() & Chr(13) _
& "Ending Sub.......Please try again", 48
End Sub
 
Johnny42,

Find returns a Range object. If it is unsuccessful, it returns Nothing and therefore, trying to access the range's Row property gives an error. Try this construct:
Code:
Dim ResultRng As Range
Dim startRow As Long

Set ResultRng = Worksheets("Sheet1").Columns("A").Find _("100", LookIn:=xlValues, LookAt:=xlWhole)
If Not ResultRng Is Nothing Then startRow = ResultRng.Row
End Sub


Regards,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top