Listbox not being populate when code is run

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,731
Office Version
  1. 2007
Platform
  1. 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 ?

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
 

Attachments

  • EaseUS_2024_02_19_15_23_03.jpg
    EaseUS_2024_02_19_15_23_03.jpg
    75.2 KB · Views: 24

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I did do the F8 procedure but it just run without and pop up errors ?
When you F8 down to the If UCase line, what is the value of UBound(arr, xlRows)
VBA Code:
        If Len(Search) > 0 Then
            For r = 2 To UBound(arr, xlRows)
                If UCase(arr(r, SearchColumn)) = Search Then
 
Upvote 0
On my way back now.

How do I advise the answer ?
Do I put cursor on the For r = 2 part ?
 
Upvote 0
@NoSparks please see attached screenshot, i hope its what you require
 

Attachments

  • EaseUS_2024_02_20_10_31_06.jpg
    EaseUS_2024_02_20_10_31_06.jpg
    20.8 KB · Views: 28
Upvote 0
My first row with data is A6 so i changed the below from A1 to a6 now it works.

Rich (BB code):
    'size data array
    arr = wsDatabase.Range("A6").CurrentRegion.Value
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,148
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top