Hi there all,
I have had limited success in posting here and so having had no response I am trying on this forum.
I have a simple userform containing a textbox and a listbox. What I want to happen is to have some code built in with the textbox_change event that takes what has been entered so far in that textbox (will be alphabetic characters) and searches for it within a specified range.
When a match is found, results should be listed in the 2 column listbox with column 1 containing an offset of the found cell by - 2 columns (same row) and column 2 containing the contents of the found cell.
There has to be some loop in doing this as if more than one match is found, it should list them all in the listbox so the user can select the item and this pulls through to another userform.
The code I have so far is not working. It DOESN'T populate the listbox and I'm not sure what I'm doing wrong.
Please can anyone help? Here is my code so far:
I have had limited success in posting here and so having had no response I am trying on this forum.
I have a simple userform containing a textbox and a listbox. What I want to happen is to have some code built in with the textbox_change event that takes what has been entered so far in that textbox (will be alphabetic characters) and searches for it within a specified range.
When a match is found, results should be listed in the 2 column listbox with column 1 containing an offset of the found cell by - 2 columns (same row) and column 2 containing the contents of the found cell.
There has to be some loop in doing this as if more than one match is found, it should list them all in the listbox so the user can select the item and this pulls through to another userform.
The code I have so far is not working. It DOESN'T populate the listbox and I'm not sure what I'm doing wrong.
Please can anyone help? Here is my code so far:
Code:
Private Sub UserForm_Initialize()
Sheets("Paste Artwork Matrix").Select
endrow = Range("G" & Rows.Count).End(xlUp).Row
Dim Data() As Variant
ReDim Data(1 To endrow - 1, 1 To 2)
For Row = 2 To endrow
Data(Row - 1, 1) = Cells(Row, "G")
Data(Row - 1, 2) = Cells(Row, "I")
Next Row
With SupplierList
.ColumnCount = 2
.ColumnWidths = "30;150"
'.RowSource = Range("G2:I798").Address
.List = Data
End With
End Sub
Private Sub TextBox1_Change()
Dim Fnd As String
Dim fCell As Range
Dim ws As Worksheet
SupplierListForm.SupplierList.Clear
Fnd = TextBox1.Value
Set ws = Worksheets("Paste Artwork Matrix")
With ws
Set fCell = .Range("I2:I979")
For i = 1 To WorksheetFunction.CountIf(fCell, Fnd)
Set fCell = .Cells.Find(what:=Fnd, After:=fCell, LookIn:=xlValues, _
lookat:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If fCell Is Nothing Then
SupplierList.Clear
Exit For
Else
With SupplierList
.AddItem fCell.Value
.List = fCell.Value
.List = fCell.Offset(0, -2).Value
End With
End If
Next i
End With
End Sub