Reputation: 14
How do I populate a combobox in a userform with the values in an Excel sheet?
Say sheet name as "Reg ALL - current".
I need to populate the value from cell AI (which is a date column).
Also I need to increment the date one day from AJ to cell BF.
Example: if AI holds value (19/06/2019) then AJ should hold (20/06/2019) and so on until BF.
Upvotes: 0
Views: 6655
Reputation: 75860
There are different ways. If you have one set range of cells (that's what I assume reading your question) that won't change, you could just set the RowSource
property of your combobox.
For example:
Apply to your situation:
AI1
holds your dateAJ1
holds formula =AI1+1
BF1
(assuming you always want to add to the value in AI1
, the formula will keep doing this for you)RowSource
property and fill in =Sheet1!AI1:BF1
Conclusion, no VBA needed at all! If I understood your question well enough that is.
Upvotes: 1
Reputation: 264
Here is simple solution Just add a button, paste this.
Dim i As Long
'Clear existing items
ComboBox1.Clear
'36 (AJ) column to 58 (BF) column
For i = 36 To 58
ComboBox1.AddItem ActiveSheet.Cells(1, i).Value
Next i
Upvotes: 0