This one has me baffled. I have a workbook containing two sheets, Inventory and PO. On the PO sheet, I have a column that has Validation turned on: Show List and Source is set to a column on the Inventory sheet. So now I can click on any of the cells in that column, and select an item from the dropdown list (the list is provided by the Inventory sheet.)
So far so good. It works as expected (I pick the item, and my macro will automatically fill the rest of the information in the rest of that row.) Except for one problem: if I happen to manually type something in, the macro fails with "Error 91, Object Variable or With Block variable not set." I've gone over Microsoft's help and Excel's help and I simply can't figure out where or why it fails. The specific code that runs and does the search on the Inventory sheet, which is where the error occurs, is as follows:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myInventorySht As Object
Set myInventorySht = Sheets("Inventory")
Dim SearchFor As Variant
Dim TheRow As Long
...
SearchFor = Target.Value
With myInventorySht.Range("B:B")
TheRow = .Cells.Find(What:=SearchFor, _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False).Row
End With
...
End Sub
Like I said, if I pick an item from the dropdown list, it works just fine. But if I happen to (accidentally) type something in, it throws an error.
Why's that?
And is it possible that when (or if) I do type something in, that it automatically fills in the dropdown list with possible matches? Kinda like how a web browser will do text-completion when you start typing in a URL?
Bookmarks