I call this Sub with a Button on a UserForm on the first worksheet. The UserForm has the user type into the text field txtItemName the name of an inventory item that is listed on “Ebay Inventory.” The code runs fine until the ‘Set rgFound’ etc line. rgFound does not have the Range where the value was found. The value is in E13 of the Ebay Inventory sheet. This error message appeared: “Run Time error ‘91’. Object variable or With block variable not set. I have tried multiple things but so far no dice. Help will be appreciated
Code
Private Sub cmdAdd_Click(
'Find item in Ebay Inventory sheet
Dim SearchFor As String 'Find this string in Ebay Inventory
Dim iRow As Long 'last data row in Ebay Inv
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim rgFound As Range
SearchFor = txtItemName
Set ws = Worksheets("Ebay Inventory")
Set ws2 = Worksheets("Poshmark Inventory")
'find first empty row in Ebay Inventory and assign it to var iRow
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row
Set rgFound = Range("E1:E" & (iRow)).Find(txtItemName, LookIn:=xlValues)
Debug.Print "Found " & SearchFor & "as value in: " & rgFound.Address
End Sub
Display More