ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,726
- Office Version
- 2007
- Platform
- Windows
Morning,
I have a userform which consists of ComboBo1 & ListBox1
In ComboBox are the selectable options of the following,
COLLECTION, LOST, RECEIVED NO DATE, RETURNED, UNKNOWN
Once an option has been selected i see in the ListBox the results in the form of Choosen Selectable Option, Customers Name, Date, Row Number.
Example.
LOST TOM JONES 22/05/2020 186
What i am looking for is that when the userform is opened the code should run itself without me having to select any option to look for
from the ComboBox & put results in ListBox like so.
COLLECTION PAUL BROWN 16/08/2019 123
COLLECTION IAN SMITH 01/01/2020 345
LOST BRIAN SMITH 22/06/2020 678
NO DATE STEVE BRYANS 05/12/2020 122
RETURNED IVOR ALAN 22/04/2016 358
UNKNOWN ABBY REECE 18/05/2020 466
Some info for you.
Option Name are in column E
Customers names are in column B
Date is in column G
Row number
Selecting a result would then take me to that on the worksheet.
The code in use basically does what i require but its coded that you need to select an option
Might be of help to you to edit / save time etc so ive supplied it below.
I have a userform which consists of ComboBo1 & ListBox1
In ComboBox are the selectable options of the following,
COLLECTION, LOST, RECEIVED NO DATE, RETURNED, UNKNOWN
Once an option has been selected i see in the ListBox the results in the form of Choosen Selectable Option, Customers Name, Date, Row Number.
Example.
LOST TOM JONES 22/05/2020 186
What i am looking for is that when the userform is opened the code should run itself without me having to select any option to look for
from the ComboBox & put results in ListBox like so.
COLLECTION PAUL BROWN 16/08/2019 123
COLLECTION IAN SMITH 01/01/2020 345
LOST BRIAN SMITH 22/06/2020 678
NO DATE STEVE BRYANS 05/12/2020 122
RETURNED IVOR ALAN 22/04/2016 358
UNKNOWN ABBY REECE 18/05/2020 466
Some info for you.
Option Name are in column E
Customers names are in column B
Date is in column G
Row number
Selecting a result would then take me to that on the worksheet.
The code in use basically does what i require but its coded that you need to select an option
Might be of help to you to edit / save time etc so ive supplied it below.
Rich (BB code):
Private Sub ListBox1_Click()
Range("E" & ListBox1.List(ListBox1.ListIndex, 3)).Select
Unload PostalIssueForm
End Sub
Private Sub ComboBox1_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 = "150;220;90;10"
If ComboBox1.Value = "" Then Exit Sub
Set r = Range("G8", Range("G" & Rows.Count).End(xlUp))
Set f = r.Find(ComboBox1.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 'DATE RECEIVED
.List(i, 1) = f.Offset(, -5).Value 'NAME
.List(i, 2) = f.Offset(, -6).Value 'DATE
.List(i, 3) = f.Row 'ROW
added = True
Exit For
End Select
Next
If added = False Then
.AddItem f.Value 'DATE RECEIVED
.List(.ListCount - 1, 1) = f.Offset(, -5).Value 'NAME
.List(.ListCount - 1, 2) = f.Offset(, -6).Value 'DATE
.List(.ListCount - 1, 3) = f.Row 'ROW
End If
Set f = r.FindNext(f)
Loop While Not f Is Nothing And f.Address <> Cell
ComboBox1 = UCase(ComboBox1)
.TopIndex = 0
Else
MsgBox "NO CUSTOMER WAS FOUND USING THAT INFORMATION", vbCritical, "POSTAGE SHEET CUSTOMER NAME SEARCH"
ComboBox1.Value = ""
ComboBox1.SetFocus
End If
End With
End Sub