ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,699
- Office Version
- 2007
- Platform
- Windows
Hi,
I have a code which works fine in respect of looking up a customers name, showing me the options in the display box & once i click the name i am taken to that person who is then in column B
This is the code.
I used the same code to look for tracking numbers & just changed the column etc etc
The code does what is supposed to do BUT when i click one of the tracking numbers in the display box i am not taken to that item of which is in column E
With the userform just above the number i wish to select as a test i click on the selected item, i see the cell on the worksheet has now been highlighted BUT im not taken to it, Im just now looking at the selected item stil on the userform
Here is the code.
Do you see why this does not take me to the selected item.
Thanks
I have a code which works fine in respect of looking up a customers name, showing me the options in the display box & once i click the name i am taken to that person who is then in column B
This is the code.
Code:
Private Sub TextBox1_Change()
Dim r As Range, f As Range, Cell As String, added As Boolean
Dim sh As Worksheet
Set sh = Sheets("POSTAGE")
sh.Select
With ListBox1
.Clear
.ColumnCount = 2
.ColumnWidths = "100;0"
If TextBox1.Value = "" Then Exit Sub
Set r = Range("B8", Range("B" & Rows.Count).End(xlUp))
Set f = r.Find(TextBox1.Value, LookIn:=xlValues, lookat:=xlPart)
If Not f Is Nothing Then
Cell = f.Address
Do
added = False
For i = 0 To .ListCount - 1
Select Case StrComp(.List(i), f.Value, vbTextCompare)
Case 0, 1
.AddItem f.Value, i
.List(i, 1) = f.Row
added = True
Exit For
End Select
Next
If added = False Then
.AddItem f.Value
.List(.ListCount - 1, 1) = f.Row
End If
Set f = r.FindNext(f)
Loop While Not f Is Nothing And f.Address <> Cell
TextBox1 = UCase(TextBox1)
Else
MsgBox "NO CUSTOMER WAS FOUND USING THAT INFORMATION", vbCritical, "POSTAGE SHEET CUSTOMER NAME SEARCH"
TextBox1.Value = ""
TextBox1.SetFocus
End If
End With
End Sub
I used the same code to look for tracking numbers & just changed the column etc etc
The code does what is supposed to do BUT when i click one of the tracking numbers in the display box i am not taken to that item of which is in column E
With the userform just above the number i wish to select as a test i click on the selected item, i see the cell on the worksheet has now been highlighted BUT im not taken to it, Im just now looking at the selected item stil on the userform
Here is the code.
Code:
Private Sub TextBox1_Change()
Dim r As Range, f As Range, Cell As String, added As Boolean
Dim sh As Worksheet
Set sh = Sheets("POSTAGE")
sh.Select
With ListBox1
.Clear
.ColumnCount = 2
.ColumnWidths = "100;0"
If TextBox1.Value = "" Then Exit Sub
Set r = Range("E8", Range("E" & Rows.Count).End(xlUp))
Set f = r.Find(TextBox1.Value, LookIn:=xlValues, lookat:=xlPart)
If Not f Is Nothing Then
Cell = f.Address
Do
added = False
For i = 0 To .ListCount - 1
Select Case StrComp(.List(i), f.Value, vbTextCompare)
Case 0, 1
.AddItem f.Value, i
.List(i, 1) = f.Row
added = True
Exit For
End Select
Next
If added = False Then
.AddItem f.Value
.List(.ListCount - 1, 1) = f.Row
End If
Set f = r.FindNext(f)
Loop While Not f Is Nothing And f.Address <> Cell
TextBox1 = UCase(TextBox1)
Else
MsgBox "NO TRACKING NUMBER WAS FOUND USING THAT INFORMATION", vbCritical, "TRACKING NUMBER SEARCH"
TextBox1.Value = ""
TextBox1.SetFocus
End If
End With
End Sub
Do you see why this does not take me to the selected item.
Thanks