Run code and show the result in listbox

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hello
i need help about this code it doesn't work and no error when i choose in the combobox1 and write data in textbox 1 based on data of sheet

VBA Code:
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    On Error Resume Next
    ii = 2
    For i = 0 To Me.ListBox1.ColumnCount
        Me.Controls("TextBox" & ii).Value = Me.ListBox1.List(ListBox1.ListIndex, i)
        ii = ii + 1
    Next
End Sub
Private Sub TextBox1_Change()
    On Error Resume Next
    Dim ws As Worksheet
    Dim V As Integer
    Dim LastRow As Integer
    Dim M As String
    Dim Q, F
    ListBox1.Clear
    If TextBox1.Text = "" Then GoTo 1
    M = TextBox1.Text
    Set ws = Sheets("Data")
    With ws
        x = ComboBox1.ListIndex + 2
        LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
        Set Q = Range(.Cells(2, x), .Cells(LastRow, x)).Find(M)
        If Not Q Is Nothing Then
            F = Q.Address
            Do
                If Application.WorksheetFunction.Search(M, Q, 0) = 1 Then
                    ListBox1.AddItem Q.Row
                    ListBox1.List(V, 1) = .Cells(Q.Row, 2).Value
                    ListBox1.List(V, 2) = .Cells(Q.Row, 3).Value
                    ListBox1.List(V, 3) = .Cells(Q.Row, 4).Text
                    ListBox1.List(V, 4) = .Cells(Q.Row, 5).Value
                    ListBox1.List(V, 5) = .Cells(Q.Row, 6).Value
                    ListBox1.List(V, 6) = .Cells(Q.Row, 7).Value
                    ListBox1.List(V, 7) = .Cells(Q.Row, 8).Value
                    ListBox1.List(V, 8) = .Cells(Q.Row, 9).Value
                    V = V + 1
                End If
                Set Q = Range(.Cells(2, x), .Cells(LastRow, x)).FindNext(Q)
            Loop While Not Q Is Nothing And Q.Address <> F
        End If
    End With
1 End Sub
 

Attachments

  • 1.PNG
    1.PNG
    139.3 KB · Views: 5
  • 2.PNG
    2.PNG
    72.9 KB · Views: 4

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
when i delete line code on error it gives me error run time error 6 overflow
 

Attachments

  • 3.PNG
    3.PNG
    2.1 KB · Views: 2
Upvote 0
Changing Integer to Long in your declarations will fix that particular error but it might not help with populating the listbox.

What are you actually trying to populate the listbox with?
 
Upvote 0
Changing Integer to Long in your declarations will fix that particular error but it might not help with populating the listbox.

What are you actually trying to populate the listbox with?
the code became slow to show the result and restart the file what i try to show data of sheet in the listbox about 9 columns
attached my file
 
Upvote 0
While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.

Pleas supply links to ALL other sites where you have asked this question.
 
Upvote 0
Excuse me, buddy , I did not get any answer. If you had obtained the answer, I wouldn't have posted my question on this site, so putting the topic link will not help anything.
 
Upvote 0
You may feel it's not necessary to includes the links, but we do. All sites have a similar policy regarding cross posting, so please supply the links as requested.
 
Upvote 0
I asked you to supply ALL links, not just one of them.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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