How to create a dynamic listbox based on the values written on the combobox using VBA excel?
up vote
0
down vote
favorite

Basically, the function of the comboboxes will be similar to a filter criteria. So every time I change the value of the combobox, the AfterUpdate event will run a code that should update the listbox to only contain values that match that criteria.
My plan was to use Autofilter to actually do this then use SpecialCells(xlCellTypeVisible) to set the rowsource.
Initial Code Idea:
Private Sub cbxSupplier_AfterUpdate()
Dim Suppler_col As Long
Supplier_col = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").ListColumns("SUPPLIER").Index
filterRangeFoilProfile.AutoFilter Field:=Supplier_col, Criteria1:=cbxSupplier.Text
lbxFoilInfoDisplay.RowSource = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").Range.SpecialCells(xlCellTypeVisible)
End Sub
However, my issue is that the Rowsource method uses a string assuming an excel formula reference such as the following: lbxFoilInfoDisplay.RowSource ="'Foil Profile'!A1:K5" and you cannot use VBA language to assign the values of the rowsource method.
The issue here is that even the values in between the filtered range will be used in the Rowsource. The work around here is to copy in a "Help worksheet" the visible cells of a table only by using SpecialCells(xlCellTypeVisible) instead, but my concern is that i'll need to clear the entire help worksheet in the After Update event for each time a combobox's value was changed.
Can I ask if there is any faster/easier/more efficient way to actually do this task?
excel vba excel-vba
add a comment |
up vote
0
down vote
favorite

Basically, the function of the comboboxes will be similar to a filter criteria. So every time I change the value of the combobox, the AfterUpdate event will run a code that should update the listbox to only contain values that match that criteria.
My plan was to use Autofilter to actually do this then use SpecialCells(xlCellTypeVisible) to set the rowsource.
Initial Code Idea:
Private Sub cbxSupplier_AfterUpdate()
Dim Suppler_col As Long
Supplier_col = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").ListColumns("SUPPLIER").Index
filterRangeFoilProfile.AutoFilter Field:=Supplier_col, Criteria1:=cbxSupplier.Text
lbxFoilInfoDisplay.RowSource = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").Range.SpecialCells(xlCellTypeVisible)
End Sub
However, my issue is that the Rowsource method uses a string assuming an excel formula reference such as the following: lbxFoilInfoDisplay.RowSource ="'Foil Profile'!A1:K5" and you cannot use VBA language to assign the values of the rowsource method.
The issue here is that even the values in between the filtered range will be used in the Rowsource. The work around here is to copy in a "Help worksheet" the visible cells of a table only by using SpecialCells(xlCellTypeVisible) instead, but my concern is that i'll need to clear the entire help worksheet in the After Update event for each time a combobox's value was changed.
Can I ask if there is any faster/easier/more efficient way to actually do this task?
excel vba excel-vba
1
Possible duplicate of How to show just filtered rows in my userform listbox
– Pᴇʜ
14 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite

Basically, the function of the comboboxes will be similar to a filter criteria. So every time I change the value of the combobox, the AfterUpdate event will run a code that should update the listbox to only contain values that match that criteria.
My plan was to use Autofilter to actually do this then use SpecialCells(xlCellTypeVisible) to set the rowsource.
Initial Code Idea:
Private Sub cbxSupplier_AfterUpdate()
Dim Suppler_col As Long
Supplier_col = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").ListColumns("SUPPLIER").Index
filterRangeFoilProfile.AutoFilter Field:=Supplier_col, Criteria1:=cbxSupplier.Text
lbxFoilInfoDisplay.RowSource = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").Range.SpecialCells(xlCellTypeVisible)
End Sub
However, my issue is that the Rowsource method uses a string assuming an excel formula reference such as the following: lbxFoilInfoDisplay.RowSource ="'Foil Profile'!A1:K5" and you cannot use VBA language to assign the values of the rowsource method.
The issue here is that even the values in between the filtered range will be used in the Rowsource. The work around here is to copy in a "Help worksheet" the visible cells of a table only by using SpecialCells(xlCellTypeVisible) instead, but my concern is that i'll need to clear the entire help worksheet in the After Update event for each time a combobox's value was changed.
Can I ask if there is any faster/easier/more efficient way to actually do this task?
excel vba excel-vba

Basically, the function of the comboboxes will be similar to a filter criteria. So every time I change the value of the combobox, the AfterUpdate event will run a code that should update the listbox to only contain values that match that criteria.
My plan was to use Autofilter to actually do this then use SpecialCells(xlCellTypeVisible) to set the rowsource.
Initial Code Idea:
Private Sub cbxSupplier_AfterUpdate()
Dim Suppler_col As Long
Supplier_col = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").ListColumns("SUPPLIER").Index
filterRangeFoilProfile.AutoFilter Field:=Supplier_col, Criteria1:=cbxSupplier.Text
lbxFoilInfoDisplay.RowSource = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").Range.SpecialCells(xlCellTypeVisible)
End Sub
However, my issue is that the Rowsource method uses a string assuming an excel formula reference such as the following: lbxFoilInfoDisplay.RowSource ="'Foil Profile'!A1:K5" and you cannot use VBA language to assign the values of the rowsource method.
The issue here is that even the values in between the filtered range will be used in the Rowsource. The work around here is to copy in a "Help worksheet" the visible cells of a table only by using SpecialCells(xlCellTypeVisible) instead, but my concern is that i'll need to clear the entire help worksheet in the After Update event for each time a combobox's value was changed.
Can I ask if there is any faster/easier/more efficient way to actually do this task?
excel vba excel-vba
excel vba excel-vba
asked 14 hours ago
Pherdindy
6215
6215
1
Possible duplicate of How to show just filtered rows in my userform listbox
– Pᴇʜ
14 hours ago
add a comment |
1
Possible duplicate of How to show just filtered rows in my userform listbox
– Pᴇʜ
14 hours ago
1
1
Possible duplicate of How to show just filtered rows in my userform listbox
– Pᴇʜ
14 hours ago
Possible duplicate of How to show just filtered rows in my userform listbox
– Pᴇʜ
14 hours ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371001%2fhow-to-create-a-dynamic-listbox-based-on-the-values-written-on-the-combobox-usin%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Possible duplicate of How to show just filtered rows in my userform listbox
– Pᴇʜ
14 hours ago