ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,731
- Office Version
- 2007
- Platform
- Windows
Hi,
I have a userform with a ComboBox & Listbox.
The Combobox has a list of which the user selects an item to find.
The column to search for this item is always column I
The found items should then be populating the Listbox but my issue is when i select an item in the Combox thats it nothing else happens & i cant see why.
This is the code in use below if you could advise please.
I did do the F8 procedure but it just run without and pop up errors ?
I have a userform with a ComboBox & Listbox.
The Combobox has a list of which the user selects an item to find.
The column to search for this item is always column I
The found items should then be populating the Listbox but my issue is when i select an item in the Combox thats it nothing else happens & i cant see why.
This is the code in use below if you could advise please.
I did do the F8 procedure but it just run without and pop up errors ?
Rich (BB code):
Private Sub ComboBox1_Change()
Dim arr As Variant
Dim r As Long, C As Long
Dim Search As String
'search in column I
Const SearchColumn As Long = 9
Search = UCase(Me.ComboBox1.Value)
'size data array
arr = wsDatabase.Range("A1").CurrentRegion.Value
With Me.ListBox1
.RowSource = ""
.Clear
If Len(Search) > 0 Then
For r = 2 To UBound(arr, xlRows)
If UCase(arr(r, SearchColumn)) = Search Then
.AddItem arr(r, SearchColumn)
For C = 1 To .ColumnCount - 2
'A 'D 'F 'G columns where data is taken to be put in listbox
.List(.ListCount - 1, C) = arr(r, Choose(C, 1, 4, 6, 7))
Next C
'row number (hidden column)
.List(.ListCount - 1, C) = r
End If
Next r
End If
End With
End Sub
Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
Dim rw As Long
Dim answer As VbMsgBoxResult
With Me.ListBox1
'get database row number
rw = Val(.Column(.ColumnCount - 1, .ListIndex))
If rw = 0 Then Exit Sub
End With
With wsDatabase
.Activate
.Range("A" & rw).Select
End With
ProgrammerWhereToOpenForm.Show
End Sub
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "AUTEL IM 508"
.AddItem "HANDY BABY"
.AddItem "KDX 2 DEVICE"
.AddItem "KDX 2 COLLECTOR"
.AddItem "NANOCOM"
.AddItem "SKP-900"
.AddItem "SKP-900 IMMO 1"
.AddItem "SKP-900 IMMO 2"
.AddItem "SKP-900 IMMO 3"
.AddItem "SKP-900 FOCUS"
.AddItem "SKP-KEYLESS 1"
.AddItem "SKP-KEYLESS 2"
.AddItem "SKP-OLD 3 PIN PLUG"
.AddItem "T300 TYPE 2A"
.AddItem "T300 TYPE 2B"
.AddItem "T300"
.AddItem "TRS 5000"
.AddItem "TRS 5000 EVO"
.AddItem "VVDI KEY TOOL"
End With
Me.StartUpPosition = 0
Me.Top = Application.Top + 70 ' MARGIN FROM TOP OF SCREEN
Me.Left = Application.Left + Application.Width - Me.Width - 90 ' LEFT / RIGHT OF SCREEN
Set wsDatabase = ThisWorkbook.Worksheets("Database")
With Me.ListBox1
.ColumnHeads = False
'size listbox
.ColumnCount = 6
.ColumnWidths = "130;240;190;190;50,0"
End With
End Sub