Neelavathy
Neelavathy

Reputation: 14

How to populate combobox dropdown in userform from Excel data?

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

Answers (2)

JvdV
JvdV

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:

enter image description here

enter image description here

Apply to your situation:

  • Cell AI1 holds your date
  • Cell AJ1 holds formula =AI1+1
  • Drag formula to cell BF1 (assuming you always want to add to the value in AI1, the formula will keep doing this for you)
  • Use 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

Arun Banakar
Arun Banakar

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

Related Questions