Hi all,
I have made a search bar on a userform that will be used for finding data values across the workbook from different worksheets.
So far the search bar can only find values from "Sheet3". I want to modify the code so it can pick up data values from all worksheets in the workbook,
The search bar pickup values regarding to range and displays each row of data within 15 different TxtBoxes.
Below is the code I have used and a screenshot of my user form.
Private Sub btnSearch_Click()
Dim ws As Worksheet
Dim strSearch As String
Dim aCell As Range, v
On Error GoTo Err
'validate text box
v = Trim(TextBox6.Value)
If Len(v) = 0 Then
MsgBox "Please Enter Data Value."
Cancel = True
Me.TextBox6.SetFocus
Exit Sub
End If
Set aCell = Sheets("sheet3").Range("A:A").Find(v, lookat:=xlWhole)
If Not aCell Is Nothing Then
With aCell.EntireRow
TextBox1.Text = .Cells(, "A").Value
TextBox2.Text = .Cells(, "B").Value
TextBox3.Text = .Cells(, "C").Value
TextBox4.Text = .Cells(, "D").Value
TextBox5.Text = .Cells(, "E").Value
TextBox7.Text = .Cells(, "F").Value
TextBox8.Text = .Cells(, "G").Value
TextBox9.Text = .Cells(, "H").Value
TextBox10.Text = .Cells(, "I").Value
TextBox11.Text = .Cells(, "J").Value
TextBox12.Text = .Cells(, "K").Value
TextBox13.Text = .Cells(, "L").Value
TextBox14.Text = .Cells(, "M").Value
TextBox15.Text = .Cells(, "N").Value
End With
Else
MsgBox "Data Value Not Found."
Cancel = True
'frmSearchTest.TextBox6.Value = ""
TextBox6.SetFocus
End If
Exit Sub
Err:
MsgBox Err.Description
End Sub
Bookmarks