ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,731
- Office Version
- 2007
- Platform
- Windows
Hi,
I am using the following code for a Textbox on my userform.
All works fine apart from say im looking for a number 07899
It has pulled in a telephone number that has a leading 0 missing.
Looking on the worksheet 0 is shown & formatted a custom.
The numbers that have a leading 0 are also formatted as custom & 0 is also shown on worksheet
I am using the following code for a Textbox on my userform.
All works fine apart from say im looking for a number 07899
It has pulled in a telephone number that has a leading 0 missing.
Looking on the worksheet 0 is shown & formatted a custom.
The numbers that have a leading 0 are also formatted as custom & 0 is also shown on worksheet
Rich (BB code):
Private Sub TextBoxTelephone_Change()
Me.Label1.Visible = False
Me.Label2.Visible = False
Me.Label3.Visible = False
Me.Label4.Visible = False
TextBoxTelephone = UCase(TextBoxTelephone)
Dim r As Range, f As Range, cell As String, added As Boolean
Dim sh As Worksheet
Set sh = Sheets("DATABASE")
sh.Select
With ListBox1
.Clear
.ColumnCount = 4
.ColumnWidths = "200;180;260;10"
If TextBoxTelephone.Value = "" Then Exit Sub
Set r = Range("W5", Range("W" & Rows.Count).End(xlUp))
Set f = r.Find(TextBoxTelephone.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.Offset(, -19).Value
.List(i, 2) = f.Offset(, -22).Value
.List(i, 3) = f.Row
added = True
Exit For
End Select
Next
If added = False Then
.AddItem f.Value
.List(.ListCount - 1, 1) = f.Offset(, -19).Value
.List(.ListCount - 1, 2) = f.Offset(, -22).Value
.List(.ListCount - 1, 3) = f.Row
End If
Set f = r.FindNext(f)
Loop While Not f Is Nothing And f.Address <> cell
TextBoxSearch = UCase(TextBoxSearch)
.TopIndex = 0
Else
MsgBox "NO SUCH TEL NUMBER FOUND", vbCritical, "POSTAGE SHEET CUSTOMER TEL NUMBER SEARCH"
TextBoxTelephone.Value = ""
TextBoxTelephone.SetFocus
End If
End With
End Sub