Populate an ActiveX combo box according to a List Box values

Status
Not open for further replies.

brendalpzm

Board Regular
Joined
Oct 3, 2022
Messages
59
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
Platform
  1. Windows
I have a ListBox that is filtered by a TextBox, but I want it ot be filter by a ComboBox as well, This means that If the TextBox is filtering specific values, the values shown in the ListBox must be shown in the ComboBox.

This is a visual example of it
1696353036149.png

And this is the code that I'm using for the filter if it's useful for reference

VBA Code:
VBA Code:
Option Explicit

Dim arrdata() As Variant 'at the beginning of all the code

Private Sub ModelCB_Change()
Call Filter_Data
End Sub

Private Sub UserFilter_Change()
Call Filter_Data
End Sub

Sub Filter_Data()
Dim i As Long, lngrow As Long
Dim tbox As String, cbox As String

Me.CarList.Clear
lngrow = 0
For i = LBound(arrdata, 1) + 1 To UBound(arrdata, 1)
If UserFilter.Value = "" Then tbox = LCase(arrdata(i, 5)) Else tbox = LCase(UserFilter.Value)
If ModelCB.Value = "" Then cbox = LCase(arrdata(i, 3)) Else cbox = LCase(ModelCB.Value)

If arrdata(i, 13) <> "completed" And LCase(arrdata(i, 5)) Like "*" & tbox & "*" And _
LCase(arrdata(i, 3)) = cbox Then
Call add_ToListbox(lngrow, i)
lngrow = lngrow + 1
End If
Next
End Sub

Private Sub UserForm_Initialize()
Dim lngindex As Long
Dim lngrow As Long

arrdata = Worksheets("Current").Range("A1").CurrentRegion.Value

With Me.lstHeaders
.ColumnCount = 7
.ColumnWidths = "180;60;255;95;75;105;65"
.Font.Size = 13
.Font.Bold = True
.Enabled = False
.AddItem
.List(lngrow, 0) = arrdata(1, 3)
.List(lngrow, 1) = arrdata(1, 4)
.List(lngrow, 2) = arrdata(1, 5)
.List(lngrow, 3) = arrdata(1, 10)
.List(lngrow, 4) = arrdata(1, 11)
.List(lngrow, 5) = arrdata(1, 13)
.List(lngrow, 6) = arrdata(1, 14)
End With

With Me.CarList
.ColumnCount = 7
.ColumnWidths = "180;60;255;95;75;105;65"
.Font.Size = 13
End With

lngrow = 0
For lngindex = LBound(arrdata, 1) + 1 To UBound(arrdata, 1)
If arrdata(lngindex, 13) <> "completed" Then
Call add_ToListbox(lngrow, lngindex)
lngrow = lngrow + 1
End If
Next lngindex
End Sub

Sub add_ToListbox(lngrow, lngindex)
With Me.CarList
.AddItem
.List(lngrow, 0) = arrdata(lngindex, 3)
.List(lngrow, 1) = arrdata(lngindex, 4)
.List(lngrow, 2) = arrdata(lngindex, 5)
.List(lngrow, 3) = arrdata(lngindex, 10)
.List(lngrow, 4) = arrdata(lngindex, 11)
.List(lngrow, 5) = arrdata(lngindex, 13)
.List(lngrow, 6) = arrdata(lngindex, 14)
End With
End Sub
[/CODE]
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Duplicate to: Populate an ActiveX combo box according to a List Box values

In future, please do not post the same question multiple times. Per Forum Rules (#12), posts of a duplicate nature will be locked or deleted.

In relation to your question here, I have closed this thread so please continue in the linked thread. If you do not receive a response, you can "bump" it by replying to it yourself, though we advise you to wait 24 hours before doing so, and not to bump a thread more than once a day.

Also please see here on how to use code tags properly. How to Post Your VBA Code
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top