I have a worksheet name called "Import File" and there is a ActiveX combobox control "Start Time" in it.
Name of ActiveX combobox control: ComboBoxStartTime
This "Import File" sheet also contains import file utility through which i can import files in same workbook. After Importing Data file through this software, i am trying to:
** Populate "ComboBoxStartTime" ActiveX combobox control from Range of data present in recently imported sheet.
There is code in standard module as:
Expand|Select|Wrap|Line Numbers
- Public Sub FillStartTimeComboBox(Datasheet As Worksheet, ByVal FirstDataRow As Long)
- Application.ScreenUpdating = False
- Dim myRange As Range
- Dim r As Range
- Dim LastDataRow As Long
- Datasheet.Activate
- LastDataRow = Cells(1000000, 1).End(xlUp).row
- 'Set the range of cells, whose values will be put into the combobox
- Set myRange = Range(Cells(FirstDataRow, 1), Cells(LastDataRow, 1))
- 'work through each cell in the range and put the value in the Spectrum combobox.
- Cells(FirstDataRow, 1).Select
- For Each r In myRange
- 'add cell value to combobox list if it is not a blank cell.
- If r.Value <> "" Then
- Sheet1.ComboBoxStartTime.AddItem r.Value
- End If
- Next r
- Application.ScreenUpdating = True
- End Sub
I am not sure in which worksheet/control event should i put this. I have called this function from Worksheet_Activate() event but in this case, code keeps running continuously. And if i put this in ComboBoxStartTime_Change(), combobox doesn't populate on selecting this worksheet and also everytime i select a value from starttime, the entire code runs and this makes process bit slower.
I'll be highly thankful if someone can help me on this.
Thanks
Prashant