ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,975
- Office Version
- 2007
- Platform
- Windows
This is the working code in use but having issues with it so having to look at an alternative way for it to work.
The issue im trying to overcome is the values that the Listbox is populated with.
On my worksheet in column C are various makes BUT i am only interested in HONDA
Also in column K are various values BUT i am only interested in BLACK, CLEAR, GREY & RED
With the 2 conditions above then load listbox
So at present with the below im loading the Listbox with values that dont to be loaded BUT im not sure how i code it so only the above takes place
The issue im trying to overcome is the values that the Listbox is populated with.
On my worksheet in column C are various makes BUT i am only interested in HONDA
Also in column K are various values BUT i am only interested in BLACK, CLEAR, GREY & RED
With the 2 conditions above then load listbox
So at present with the below im loading the Listbox with values that dont to be loaded BUT im not sure how i code it so only the above takes place
VBA Code:
Private Sub UserForm_Initialize()
Me.StartUpPosition = 0
Me.Top = Application.Top + 15 ' MARGIN FROM TOP OF SCREEN
Me.Left = Application.Left + Application.Width - Me.Width - 330 ' LEFT / RIGHT OF SCREEN HIGHER NUMBER MOVES FORM TO THE LEFT
TextBox1.Visible = False
TextBox1.Value = "HONDA"
Dim r As Range, f As Range, Cell As String, added As Boolean
Dim sh As Worksheet
Dim i As Long
Set sh = Sheets("MCLIST")
sh.Select
With ListBox1
.Clear
.ColumnCount = 4
.ColumnWidths = "100;170;70;10"
Set r = Range("C8", Range("C" & Rows.Count).End(xlUp))
Set f = r.Find(TextBox1.Value, After:=r.Cells(r.Count), LookIn:=xlValues, LookAt:=xlPart)
If Not f Is Nothing Then
Cell = f.Address
Do
If Len(Cells(f.Row, "K").Value) <> 0 Then
.AddItem f.Value
.List(.ListCount - 1, 1) = f.Offset(, 1).Value ' MODEL
.List(.ListCount - 1, 2) = f.Offset(, 6).Value ' YEAR
.List(.ListCount - 1, 3) = f.Offset(, 8).Value ' CONNECTOR USED
.List(.ListCount - 1, 4) = f.Row
End If
Set f = r.FindNext(f)
Loop While f.Address <> Cell
.TopIndex = 0
End If
End With
TextBox2.Text = ActiveSheet.Range("K1").Value ' BLACK
TextBox3.Text = ActiveSheet.Range("K2").Value ' CLEAR
TextBox4.Text = ActiveSheet.Range("K3").Value ' GREY
TextBox5.Text = ActiveSheet.Range("K4").Value ' RED
End Sub