ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,832
- Office Version
- 2007
- Platform
- Windows
Hi,
Im using the code below.
On the userform in TextBox1 i type a value to search for.
Pressing the commandbutton called FindThe Value it searches for all the matches to what i entered in TextBox1
ListBox1 then shows all the row numbers that have a match.
THE ABOVE ALL WORKS FINE.
Clicking each row number in Listbox1 selects the customer on my worksheet in column A until the required item is found.
Closing the userform leave the customer readily selected on my worksheet.
So here is my example.
I search for MIT 11
All the matches are now shown in ListBox1
I clicked each row number BUT as opposed selecting the customer in column A have the code select the cell that MIT 11 was found in.
So as opposed A123 being Mr Smith have the actual cell R123 selected.
Sometimes my worksheet columns are off the right hand side of the screen & im being shown Mr Simth in column A as opposed to the searched value of MIT 11 in R123
Please advise
Im using the code below.
On the userform in TextBox1 i type a value to search for.
Pressing the commandbutton called FindThe Value it searches for all the matches to what i entered in TextBox1
ListBox1 then shows all the row numbers that have a match.
THE ABOVE ALL WORKS FINE.
Clicking each row number in Listbox1 selects the customer on my worksheet in column A until the required item is found.
Closing the userform leave the customer readily selected on my worksheet.
So here is my example.
I search for MIT 11
All the matches are now shown in ListBox1
I clicked each row number BUT as opposed selecting the customer in column A have the code select the cell that MIT 11 was found in.
So as opposed A123 being Mr Smith have the actual cell R123 selected.
Sometimes my worksheet columns are off the right hand side of the screen & im being shown Mr Simth in column A as opposed to the searched value of MIT 11 in R123
Please advise
VBA Code:
Private Sub FindTheValue_Click()
Application.ScreenUpdating = False
Dim fnd As Range, srcRng As Range, i As Long, sAddr As String, srcWS As Worksheet, dic As Object
Set srcWS = Sheets("DATABASE")
Set srcRng = srcWS.Range("C6", srcWS.Range("AC" & Rows.Count).End(xlUp))
Set dic = CreateObject("scripting.dictionary")
If TextBox1.Value = "" Then
MsgBox "PLEASE TYPE A VALUE TO SEARCH FOR", vbCritical + vbOKOnly, "SEARCH BOX IS EMPTY"
Else
Set fnd = srcRng.Find(Me.TextBox1.Value, LookIn:=xlValues, LookAt:=xlPart)
If Not fnd Is Nothing Then
sAddr = fnd.Address
Do
If Not dic.Exists(fnd.Row) Then
dic.Add fnd.Row, Nothing
ListBox1.AddItem fnd.Row
End If
Set fnd = srcRng.FindNext(fnd)
Loop While fnd.Address <> sAddr
sAddr = ""
Else
MsgBox "NOTHING TO MATCH THE SEARCH VALUE", vbCritical, "VALUE NOT FOUND MESSAGE"
TextBox1.Value = ""
TextBox1.SetFocus
End If
End If
Application.ScreenUpdating = True
End Sub
Private Sub ListBox1_Click()
Range("A" & ListBox1.List(ListBox1.ListIndex, 0)).Select
End Sub