搜索数字和单词 vba sc

Search numbers and words vba sc

我是 VBA 的新手,想写一个代码来查找 excel sheet

中的数字和单词

在这段代码中我可以搜索数字但不能搜索单词

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 这对我有用!

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