View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default "Object Variable or With Block Variable Not Set" error help request

Ken,

It isn't finding it. Try this

Sub FindCRN()
' On Error GoTo errorHandler
Dim EnteredCRN As String
Dim FoundInRow As Integer

EnteredCRN = Worksheets("Enter Data").Range("B4").Value
MsgBox ("EnteredCRN = " & EnteredCRN)
On Error Resume Next
FoundInRow = Worksheets("Classes").Columns("C").Find(EnteredCRN , _
LookIn:=xlValues, lookat:=xlWhole).Row
On Error GoTo 0
If FoundInRow = 0 Then
GoTo errorHandler
Else
MsgBox ("FoundInRow = " & FoundInRow)
Sheets("Enter Data").Range("B7").Value = Sheets("Classes").Range("A"
& FoundInRow)
Sheets("Enter Data").Range("B8").Value = Sheets("Classes").Range("B"
& FoundInRow)
Sheets("Enter Data").Range("B9").Value = Sheets("Classes").Range("F"
& FoundInRow)
Sheets("Enter Data").Range("B10").Value =
Sheets("Classes").Range("H" & FoundInRow)
Sheets("Enter Data").Range("B11").Value =
Sheets("Classes").Range("I" & FoundInRow)
Sheets("Enter Data").Range("B5").Value = Sheets("Classes").Range("D"
& FoundInRow)
End
End If

errorHandler:
MsgBox "That CRN was not found......Please try again"
End Sub



--

HTH

RP
(remove nothere from the email address if mailing direct)


"Ken Loomis" wrote in message
...
I am getting a "Object Variable or With Block Variable Not Set" error in
the following line from the code below:

FoundInRow = Worksheets("Classes").Columns("C").Find(EnteredCRN , _
LookIn:=xlValues, lookat:=xlWhole).Row

I just don't do enough of this Excel VBA programming to be able to figure
that out. Can someone please help?

Thanks,
Ken



Sub FindCRN()
' On Error GoTo errorHandler
Dim EnteredCRN As String
Dim FoundInRow As Integer

EnteredCRN = Worksheets("Enter Data").Range("B4").Value
MsgBox ("EnteredCRN = " & EnteredCRN)
FoundInRow = Worksheets("Classes").Columns("C").Find(EnteredCRN , _
LookIn:=xlValues, lookat:=xlWhole).Row
MsgBox ("FoundInRow = " & FoundInRow)
Sheets("Enter Data").Range("B7").Value = Sheets("Classes").Range("A" &
FoundInRow)
Sheets("Enter Data").Range("B8").Value = Sheets("Classes").Range("B" &
FoundInRow)
Sheets("Enter Data").Range("B9").Value = Sheets("Classes").Range("F" &
FoundInRow)
Sheets("Enter Data").Range("B10").Value = Sheets("Classes").Range("H"

&
FoundInRow)
Sheets("Enter Data").Range("B11").Value = Sheets("Classes").Range("I"

&
FoundInRow)
Sheets("Enter Data").Range("B5").Value = Sheets("Classes").Range("D" &
FoundInRow)

End
errorHandler:
MsgBox "That CRN was not found......Please try again")
End Sub