Question : Auto Fill Combo Box Using VBA

Hello all.
I have two Worksheets.  One is called "Form"...the other is called "Data".
I have a Combo Box called "ComboBox1" on the Form worksheet.  I would like to fill it with Data from the Data Worksheet.  The Range is A1 - A19

Will award an additional 100 points if you have code to add the same data to a Combo Box on an actual Form.

This could be done in the Open Event of the Workbook.

Thanks
WonHop



Answer : Auto Fill Combo Box Using VBA

Oh... you wanted a dynamic range for the worksheet combo box....


Well, keep in mind that all of the code we provided is for a fixed range which you specified. (A1:A19)


If you want this to be dynamic, we'll have to make a few adjustments.


For the worksheet combobox... you can add this to module of the Form sheet.

Private Sub Worksheet_Activate()

    i = Sheets("Data").Range("A65536").End(xlUp).Row
    ComboBox1.ListFillRange = "Data!A1:A" & i
   
End Sub


And for the Form based combo, you can use this Load (initialize) event


Private Sub UserForm_Initialize()

    i = Sheets("Data").Range("A65536").End(xlUp).Row
    For Each TmpRng In Sheets("Data").Range("A1:A" & i).Cells
        ComboBox1.AddItem TmpRng.Value
    Next
   
End Sub


WATYF
Random Solutions  
 
programming4us programming4us