When I use wb.Sheets(1).Range("A:A").Find(What:=ID, LookIn:=xlValues) I get error 91 - Object Variable or With Block not set. When I use Sheet1.Range("A:A").Find(What:=ID, LookIn:=xlValues) it returns correct value.
Why the difference?
Is there a flowchart I can reference or any simple information available to understand which sub-commands (I don't know the proper word) work with ThisWorkbook and Sheets(#) versus Sheet#.Whatever?
I am hesitant to use Sheet("Name") because names might change later. I am using ThisWorkbook rather than ActiveWorkbook to keep all code attached to the appropriate workbook.
Anything you can offer for simple reference info would be great. I have researched, but still don't understand which sub-commands work with which parent commands. (Again, probably wrong terminology).
Private Sub lstExample_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim wb As Workbook
Dim I As Integer
Dim ID As String
Dim findValue As Range
Set wb = ThisWorkbook
'Get the values of the selected row in listbox on doubleclick
For I = 0 To lstExample.ListCount - 1
If lstExample.Selected(I) = True Then
'Set listbox column 1 as ID value to find
ID = lstExample.List(I, 1)
End If
Next I
'Match ID (column A) on Sheet1
Set findValue = wb.Sheets(1).Range("A:A").Find(What:=ID, LookIn:=xlValues)
MsgBox findValue
End Sub
msgboxline? Because that will bomb in the event that the ID isn't found. Are you certain that there is a sheet with an index of 1 in your workbook (I can't imagine how there wouldn't be, but who knows)?