ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,226
- Office Version
- 2007
- Platform
- Windows
I am using the code below.
On the userform i enter ES into TextBox1
The results are them shown in the ListBox
One thing i notice is that there is no row number shown in the ListBox ?
If i select a value with no row number shown i see a RTE1004 Method range of object Global failed.
If i select a value which does have a row number then i am taken to that item on the worksheet.
What i dont understand is why there should be any entries without row numbers because my worksheet has row numbers obviously for each customer ?
PLEASE SEE SCREEN SHOTS
On the userform i enter ES into TextBox1
The results are them shown in the ListBox
One thing i notice is that there is no row number shown in the ListBox ?
If i select a value with no row number shown i see a RTE1004 Method range of object Global failed.
If i select a value which does have a row number then i am taken to that item on the worksheet.
What i dont understand is why there should be any entries without row numbers because my worksheet has row numbers obviously for each customer ?
PLEASE SEE SCREEN SHOTS
VBA Code:
Private Sub ListBox1_Click()
Set sh = Sheets("POSTAGE")
sh.Select
Range("I" & ListBox1.List(ListBox1.ListIndex, 3)).Select
Unload PostageUserNameSearch
End Sub
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 = 4
.ColumnWidths = "240;100;280;50"
If TextBox1.Value = "" Then Exit Sub
Set r = Range("I8", Range("I" & 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 'Item
.List(1, 3) = f.Row 'Row Number
.List(i, 2) = f.Offset(, -7).Value 'Customer
.List(i, 1) = f.Offset(, -2).Text 'Date
added = True
Exit For
End Select
Next
If added = False Then
.AddItem f.Value 'Item
.List(.ListCount - 1, 3) = f.Row 'Row Number
.List(.ListCount - 1, 2) = f.Offset(, -7).Value 'Customer
.List(.ListCount - 1, 1) = f.Offset(, -2).Text 'Date
End If
Set f = r.FindNext(f)
Loop While Not f Is Nothing And f.Address <> Cell
TextBox1 = UCase(TextBox1)
.TopIndex = 0
Else
MsgBox "NO USER NAME WAS FOUND USING THAT INFORMATION", vbCritical, "POSTAGE SHEET USER NAME SEARCH"
TextBox1.Value = ""
TextBox1.SetFocus
End If
End With
End Sub