I'm very new to VBA and tying to write a code that would find numbers and words in excel sheet
in this code i can search number but cannot search words
Private Sub CommandButton5_Click()
Dim product_id As String
product_id = Trim(TextBox1.Text)
lastrow = Worksheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrow
If Worksheets("sheet1").Cells(i, 1).Value = product_id Then
TextBox2.Text = Worksheets("sheet1").Cells(i, 2).Value
TextBox3.Text = Worksheets("sheet1").Cells(i, 3).Value
TextBox4.Text = Worksheets("sheet1").Cells(i, 4).Value
End If
Next
End Sub
O.k this work for me!
Private Sub CommandButton3_Click()
Dim M As Long
Me.ListBox1.Clear
Me.ListBox1.AddItem
For a = 1 To 5
Me.ListBox1.List(0, a - 1) = Sheet1.Cells(1, a)
Next a
Me.ListBox1.Selected(0) = True
For M = 2 To Sheet1.Range("a1000").End(xlUp).Offset(1, 0).Row
For s = 1 To 5
g = Application.WorksheetFunction.CountIf(Sheet1.Range("a" & 2, "E" & M), Sheet1.Cells(M, s))
If g = 1 And LCase(Sheet1.Cells(M, s)) = LCase(Me.TextBox1) Or g = 1 And Sheet1.Cells(M, s) = Val(TextBox1) Then
Me.ListBox1.AddItem
For x = 1 To 5
Me.ListBox1.List(ListBox1.ListCount - 1, x - 1) = Sheet1.Cells(M, x)
Next x
End If
Next s
Next M
End Sub