Programming for Everybody: search combobox in vba excel
Showing posts with label search combobox in vba excel. Show all posts
Showing posts with label search combobox in vba excel. Show all posts

VBA code for search ComboBox in userform Microsoft #Excel With Source Code



 Private Sub ComboBox1_Change()

Dim ws As Worksheet

Set ws = ThisWorkbook.Sheets("Sheet1")

Dim i As Integer

For i = 1 To ws.UsedRange.Rows.Count

If Me.ComboBox1.Column(0) = ws.Cells(i, 2).Value Then

Me.id_txt.Text = ws.Cells(i, 1).Value

Me.math_txt.Text = ws.Cells(i, 3).Value

Me.geo_txt.Text = ws.Cells(i, 4).Value

Me.chem_txt.Text = ws.Cells(i, 5).Value

Me.his_txt.Text = ws.Cells(i, 6).Value

Me.com_txt.Text = ws.Cells(i, 7).Value

End If

Next i

End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()

Dim lastrow, i As Integer

lastrow = Sheet1.Cells(Rows.Count, "B").End(xlUp).Row

For i = 2 To lastrow

Dim vs As String

vs = Sheet1.Cells(i, "B")

Me.ComboBox1.AddItem vs

Next i

End Sub