ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,806
- Office Version
- 2007
- Platform
- Windows
I have a userform where the user types a customers name in a Textbox.
Using a command button the code searches for that typed value & then lists the results in the Listbox.
The results are shown as per screenshot where you can see from day 1 a low row number & also an old date.
The user is then at present having to scroll for a while to see newer results.
My question is can the results be reversed so as opposed older values at the top then scroll to new have it so new values are at the top then scroll to older results.
Maybe the search is looking from Row 7 down the page to todays current row which is 2312 when maybe we can alter it to search from last current row with values up to row 7,just a thought/
The code for the Listbox is supplied below.
Using a command button the code searches for that typed value & then lists the results in the Listbox.
The results are shown as per screenshot where you can see from day 1 a low row number & also an old date.
The user is then at present having to scroll for a while to see newer results.
My question is can the results be reversed so as opposed older values at the top then scroll to new have it so new values are at the top then scroll to older results.
Maybe the search is looking from Row 7 down the page to todays current row which is 2312 when maybe we can alter it to search from last current row with values up to row 7,just a thought/
The code for the Listbox is supplied below.
VBA Code:
Private Sub CommandButton2_Click()
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 = "220;130;160;10"
If TextBox8.Value = "" Then Exit Sub
Set r = Range("B8", Range("B" & Rows.count).End(xlUp))
Set f = r.Find(TextBox8.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 'col B
.List(i, 1) = f.Offset(, 2).Value 'col D
.List(i, 2) = f.Offset(, 5).Text 'col G .TEXT is used as date in Listbox was shown as 12/17/2020 as opposed 17/12/2020
.List(i, 3) = f.Row 'row
added = True
Exit For
End Select
Next
If added = False Then
.AddItem f.Value 'col B
.List(.ListCount - 1, 1) = f.Offset(, 2).Value 'col D
.List(.ListCount - 1, 2) = f.Offset(, 5).Text 'col G .TEXT is used as date in Listbox was shown as 12/17/2020 as opposed 17/12/2020
.List(.ListCount - 1, 3) = f.Row 'row
End If
Set f = r.FindNext(f)
Loop While Not f Is Nothing And f.Address <> Cell
TextBox8 = UCase(TextBox8)
.TopIndex = 0
Else
MsgBox "NO CUSTOMER WAS FOUND USING THAT INFORMATION", vbCritical, "POSTAGE SHEET CUSTOMER NAME SEARCH"
TextBox8.Value = ""
TextBox8.SetFocus
End If
End With
End Sub