如何解决搜索数字和单词vba sc
我是VBA的新手,我想编写一个可以在Excel工作表中查找数字和单词的代码
在此代码中,我可以搜索号码,但不能搜索单词
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
解决方法
好的,这对我有用!
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。