VBA user form search code

FGaxha

Board Regular
Joined
Jan 10, 2023
Messages
221
Office Version
  1. 365
Platform
  1. Windows
Hi Masters,
I have a vbs code for user form search:
Ia pooling data only for January, and I need to pull data for February, march, April. Please help?

Private Sub TextBox1_Change()
Dim i As Long
Me.TextBox1 = Format(StrConv(Me.TextBox1, vbLowerCase))
Me.ListBox1.Clear
Me.ListBox1.AddItem "OEM Name"
Me.ListBox1.List(0, 1) = "Platform"
Me.ListBox1.List(0, 2) = "Jan"
Me.ListBox1.List(0, 3) = "Feb"
Me.ListBox1.List(0, 4) = "Mar"
Me.ListBox1.Selected(0) = True
For i = 2 To Sheet1.Range("A1000000").End(xlUp).Row
For X = 1 To Len(Sheet1.Cells(i, 1))
a = Me.TextBox1.TextLength
If LCase(Mid(Sheet1.Cells(i, 1), X, a)) = Me.TextBox1 And Me.TextBox1 <> "" Then
Me.ListBox1.AddItem Sheet1.Cells(i, 1)
Me.ListBox1.List(ListBox1.ListCount - 1, 1) = "" & Sheet1.Cells(i, 2)
Me.ListBox1.List(ListBox1.ListCount - 1, 2) = "" & Sheet1.Cells(i, 3)
End If
Next X
Next i
End Sub

Private Sub UserForm_Click()

End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try this:

VBA Code:
Private Sub TextBox1_Change()
  Dim i As Long, j As Long
  
  Me.TextBox1 = Format(StrConv(Me.TextBox1, vbLowerCase))
  With ListBox1
    .List = Sheet1.Range("A1:N1").Value
    .Clear
    .AddItem
    
    'I assume the headers are in row 1 of sheet1
    For j = 1 To 14
      .List(.ListCount - 1, j - 1) = "" & Sheet1.Cells(1, j)
    Next
    For i = 2 To Sheet1.Range("A1000000").End(xlUp).Row
      If LCase(Sheet1.Range("A" & i).Value) Like "*" & TextBox1.Text & "*" Then
        .AddItem
        For j = 1 To 14
          .List(.ListCount - 1, j - 1) = "" & Sheet1.Cells(i, j)
        Next j
      End If
    Next i
  End With
End Sub
Pull data up to column 14, I assume it is December, if you only need until April, then change the number 14 to a 6.


----- --
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
----- --
 
Upvote 0
Hi Dante,
Thanks for the reoly, it does not work, it is pulling data just for first three columns.
Yeas header is A1 to N
 
Upvote 0
You must change the ColumnCount property of the listbox to 14

1698686582525.png
 
Upvote 1
Solution
You right, It works great after changing to 14,.
Thank you for your help
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

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