PDA

View Full Version : Solved: Not recognizing variable or range?



russkie
10-10-2005, 01:54 PM
Hey guys.
Listen i have no clue what the problem is here...
This is the code:


With Worksheets("Sheet1").Range("B:B")
Set ItemCell = .Find(scanned, LookAt:=xlWhole)
If Not ItemCell Is Nothing Then
GoTo CheckPrice
Else
AddItemOrCont = MsgBox("This Item is not in our inventory." & vbLf & vbLf & "Would you like to add this item now?", vbYesNo + vbQuestion, "YF.")
'Yes to goto then add new item, No then restart...
If AddItemOrCont = vbYes Then
addnewitem
cntn = MsgBox("Item Added successfully.", vbOKOnly, "YF")
SHProtect
GoTo CheckPrice
Else
GoTo GetBookInfo
End If
End If
End With

CheckPrice:
With Worksheets("Sheet1")
'Check if the price of the Item is in our inventory, if not ask for it
If (ItemCell.Offset(0, 2).Value = "") Then
price = InputBox("Please Enter the Price of the Item.", "SHalom Nathalie")
If (price = "") Then
MsgBox "You did not enter a value, Program will now exit."
GoTo endprgrm
End If


OK so, "addnewitem" is a sub. If "scanned" does not exist in B:B then run that sub. So it runs the sub, all is cool. But when it continues, it causes an error at:

If (ItemCell.Offset(0, 2).Value = "") Then

just incase, the error is:
"Object variable or With block variable not set"

anyone any clue what on earth??

Mucho Appreciato! :banghead:

Bob Phillips
10-10-2005, 02:03 PM
If scanned is not found, ItemCell is Nothing, so you can't offset it as it is not a valid object variable.

russkie
10-10-2005, 02:08 PM
Thats wild...
can't believe that didnt hit me, thanks man.
:clap: