Consulting

Results 1 to 7 of 7

Thread: adjusted code show the data in listbox on userform

  1. #1

    adjusted code show the data in listbox on userform

    hello
    i have error about my code when i choose in combobox and write in textbox it gives me highlight this
    If Application.WorksheetFunction.Search(M, Q, 0) = 1 Then
    and gives me error
    run time 1004
    and this is my code
    HTML 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 Long  
      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 With1 
    End Sub
    attached file
    Attached Files Attached Files

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,081
    try:
    .Search(M, Q, 1)
    or:
    .Search(M, Q)
    p45cal - - - - -This is my signature, it appears after all my posts. Below is not directed at anyone in particular - so don't take offence! - (You might guess why it's there though)
    If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Quote Originally Posted by p45cal View Post
    try:
    .Search(M, Q, 1)
    or:
    .Search(M, Q)
    thanks it really works but the code is very slow is there any why make faster something add line code

  4. #4
    Moderator VBAX Guru Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    3,868
    Location
    Maghari, any chance you might have posted this issue elsewhere?
    Remember To Do the Following....
    Use tags when posting code to the thread,
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  5. #5
    Quote Originally Posted by Aussiebear View Post
    Maghari, any chance you might have posted this issue elsewhere?
    yes in another web it delay to respond my problem that's why i repeat my subject excuse me if this Violation with the laws of the forum inform me , please

  6. #6
    Moderator VBAX Guru Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    3,868
    Location
    Yes. In so far as you have an obligation to indicate to those who use this forum. In fact I'd suggest its a common courtesy that all forums request.
    Remember To Do the Following....
    Use tags when posting code to the thread,
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    Knowledge Base Approver VBAX Wizard
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,081
    p45cal - - - - -This is my signature, it appears after all my posts. Below is not directed at anyone in particular - so don't take offence! - (You might guess why it's there though)
    If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •