I have a 2 column Excel spreadsheet that looks roughly like this:
ProjectID Keyword
ABC1 employment
ABC1 marketing
ABC1 personnel
XYZ1 catering
XYZ1 transport
I also have an excel form with a textbox where a user can type in a projectID. On entering a projectID, I would like to search the spreadsheet for this projectID and load the corresponding keyword(s) into a list box on my form. Here's my code but I always get an error saying 'can't find .Find method of Range object'
Can anyone help??
Dim projectID As String
Dim search
Dim RowNo As Long
Dim keyword As String
Dim c As Range
projectID = TextBox6.Text
'first find the projectID and look in the adjacent cell
'to find the keyword. Add the key word to the lstSelection
'repeat for more keywords for this projectID
With Worksheets("Keywords".Range("A2:A300"
Set c = .Find(projectID)
If Not c Is Nothing Then
search = c.Address
RowNo = c.Row
Do
Range("A" & RowNo).Offset(0, 1).Value = keyword
lstSelection.AddItem keyword
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> search
End If
End With
ProjectID Keyword
ABC1 employment
ABC1 marketing
ABC1 personnel
XYZ1 catering
XYZ1 transport
I also have an excel form with a textbox where a user can type in a projectID. On entering a projectID, I would like to search the spreadsheet for this projectID and load the corresponding keyword(s) into a list box on my form. Here's my code but I always get an error saying 'can't find .Find method of Range object'
Can anyone help??
Dim projectID As String
Dim search
Dim RowNo As Long
Dim keyword As String
Dim c As Range
projectID = TextBox6.Text
'first find the projectID and look in the adjacent cell
'to find the keyword. Add the key word to the lstSelection
'repeat for more keywords for this projectID
With Worksheets("Keywords".Range("A2:A300"
Set c = .Find(projectID)
If Not c Is Nothing Then
search = c.Address
RowNo = c.Row
Do
Range("A" & RowNo).Offset(0, 1).Value = keyword
lstSelection.AddItem keyword
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> search
End If
End With