7/9/2023 0 Comments Ms word combo box additemSub Populate_Combobox_Worksheet_Collection()ĭim vaData As Variant 'the list, stored in a variantĭim ncData As New VBA.Collection 'the list, stored in a collectionĭim lnCount As Long 'the count used in the On Error Resume Next loop.ĭim vaItem As Variant 'a variant representing the type of items in ncData ![]() ![]() With wsSheet.OLEObjects("ComboBox1").Object 'display the unique values in vaData in the combo box already in existence on the worksheet. 'clean up the contents of the temporary data storage RnData.AdvancedFilter Action:=xlFilterCopy, _ 'Set the range equal to the data, and then (temporarily) copy the unique values of that data to the L column. Set wsSheet = wbBook.Worksheets("Sheet1") 'Variant to contain the data to be placed in the combo box. 'The Excel workbook and worksheets that contain the data, as well as the range placed on that data NET & Excel Sub Populate_Combobox_Worksheet() Sample code provided by: Dennis Wallentin, VSTO &. The first example uses the AdvancedFilter method of the Range object and the second uses the Collection object. ![]() These examples show different approaches for taking a list from a spreadsheet and using it to populate a combo box control using only the unique values.
0 Comments
Leave a Reply. |