Professional Documents
Culture Documents
html
HOME
CONTENTS
INDEX
How to fill a Combobox / Listbox
LANGUAGE
EXAMPLE FILE
SUGGESTIONS
1 of 15 19/Nov-17, 11:02
VBA for smarties How to fill a Combobox / Listbox http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html
5 Populate: Evaluate
1.2 A list of numbers
5.1.1 all decimals
5.1.2 Ucase alphabet
5.1.3 Lcase alphabet ComboBox1.List = Array(1, 2, 3)
5.1.4 numbers
interval 5 1.3 A list of dates
5.1.5 numbers
interval 7 ComboBox1.List = Array(Date, Date + 1, Date + 2)
2 of 15 19/Nov-17, 11:02
VBA for smarties How to fill a Combobox / Listbox http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html
2.2 Subfolders
2.3 Worksheet
ComboBox1.List = Application.GetCustomListContents(1)
3.2 weekdaynames
ComboBox1.List = Application.GetCustomListContents(2)
ComboBox1.List = Application.GetCustomListContents(3)
3.4 monthnames
ComboBox1.List = Application.GetCustomListContents(4)
3 of 15 19/Nov-17, 11:02
VBA for smarties How to fill a Combobox / Listbox http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html
ComboBox1.List = Application.GetCustomListContents(Application.CustomListCount)
4.1 a column
UBound(ComboBox1.List)=9
UBound(ComboBox1.List, 2)=0
4.2 a row
UBound(ComboBox1.List)=0
UBound(ComboBox1.List, 2)=9
If you want to show all columns you will have to change the property columncount:
combobox1.columncount=ubound(combobox1.list,2)+1
4.3 a range
ComboBox1.List = Sheets(1).Cells(1,1).Resize(10,10).Value
UBound(ComboBox1.List)=9
UBound(ComboBox1.List, 2)=9
If you want to show all columns you will have to change the property columncount:
combobox1.columncount=ubound(combobox1.list,2)+1
ComboBox1.List =
Application.Transpose(Filter([transpose(if(countif(offset($A$1,,,row(A1:A100)),A1:A100)=1,A1:A100,"~"))], "~", False))
or
sn = Sheets(1).Range("A1:A100")
With CreateObject("scripting.dictionary")
For Each cl In sn
If cl<>"" And Not .exists(cl) Then .Add cl, Nothing
Next
ComboBox1.List = .keys
End With
With CreateObject("System.Collections.ArrayList")
For Each cl In sn
If cl<>"" And Not .contains(cl) Then .Add cl
Next
.Sort
ComboBox1.List = Application.Transpose(.toarray())
End With
combobox1.list = Application.Transpose(Filter([index(if(countif(offset($A$1,,,,column(A1:AZ1)),A1:AZ1)=1,A1:AZ1),)],
"False", False))
sn = Sheets(1).Range("A1:AZ1")
With CreateObject("scripting.dictionary")
For Each cl In sn
If cl<>"" And Not .exists(cl) Then .Add cl, Nothing
Next
ComboBox1.List = .keys
End With
sn= Sheets(1).Range("A1:AZ1")
With CreateObject("System.Collections.ArrayList")
For Each cl In sn
If cl<>"" And Not .contains(cl) Then .Add cl
Next
.Sort
4 of 15 19/Nov-17, 11:02
VBA for smarties How to fill a Combobox / Listbox http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html
ComboBox1.List = Application.Transpose(.toarray())
End With
sn = Sheets(1).Range("A1:AZ100")
With CreateObject("scripting.dictionary")
For Each cl In sn
If cl<>"" And Not .exists(cl) Then .Add cl, Nothing
Next
ComboBox1.List = .keys
End With
sn= Sheets(1).Range("A1:AZ100")
With CreateObject("System.Collections.ArrayList")
For Each cl In sn
If cl<>"" And Not .contains(cl) Then .Add cl
Next
.Sort
ComboBox1.List = Application.Transpose(.toarray())
End With
ComboBox1.List = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
ComboBox1.List = Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")
ComboBox1.List = [row(1:10)-1]
ComboBox1.List = [index(row(1:10)-1,)]
ComboBox1.List = [index(char(row(48:57)),)]
ComboBox1.List = [transpose(char(row(48:57)))]
ComboBox1.List = Evaluate("row(1:10)-1")
ComboBox1.List = Evaluate("index(char(row(48:57)),)")
ComboBox1.List = Evaluate("transpose(char(row(48:57)))")
ComboBox1.List = [index(char(64+row(1:26)),)]
ComboBox1.List = [index(char(96+row(1:26)),)]
ComboBox1.List = [index(5*(row(1:10)-1),)]
ComboBox1.List = [index(7*(row(1:10)-1),)]
5.2 Monthnames
ComboBox1.List = [index(text(date(2015,row(1:12),1),"mmmm"),)]
5 of 15 19/Nov-17, 11:02
VBA for smarties How to fill a Combobox / Listbox http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html
ComboBox1.List = [index(text(date(2015,row(1:12),1),"mmm"),)]
6 of 15 19/Nov-17, 11:02
VBA for smarties How to fill a Combobox / Listbox http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html
7 of 15 19/Nov-17, 11:02
VBA for smarties How to fill a Combobox / Listbox http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html
8 of 15 19/Nov-17, 11:02
VBA for smarties How to fill a Combobox / Listbox http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html
5.3 Weekdaynames
ComboBox1.List = [index(text(row(1:7),"dddd"),)]
ComboBox1.List = [index(text(row(2:8),"dddd"),)]
ComboBox1.List = [index(text(row(1:7),"ddd"),)]
ComboBox1.List = [index(text(row(2:8),"ddd"),)]
9 of 15 19/Nov-17, 11:02
VBA for smarties How to fill a Combobox / Listbox http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html
10 of 15 19/Nov-17, 11:02
VBA for smarties How to fill a Combobox / Listbox http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html
11 of 15 19/Nov-17, 11:02
VBA for smarties How to fill a Combobox / Listbox http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html
5.4 Dates
ComboBox1.List = [index(today()-weekday(today(),2)+row(1:7),)]
ComboBox1.List = [index(Text(today()-weekday(today(),2)+row(1:7),"dd-mm-yyyy"),)]
12 of 15 19/Nov-17, 11:02
VBA for smarties How to fill a Combobox / Listbox http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html
ComboBox1.List = [index(today()-weekday(today(),2)-7+row(1:7),)]
ComboBox1.List = [index(Text(today()-weekday(today(),2)-7+row(1:7),"dd-mm-yyyy"),)]
ComboBox1.List = [index(today()-weekday(today(),2)+row(8:14),)]
ComboBox1.List = [index(Text(today()-weekday(today(),2)+row(8:14),"dd-mm-yyyy"),)]
ComboBox1.List =
[index(date(year(today()),month(today()),0)+row(offset(A1,,,day(date(year(today()),month(today())+1,0)),1)),)]
ComboBox1.List =
[index(text(date(year(today()),month(today()),0)+row(offset(A1,,,day(date(year(today()),month(today())+1,0)),1)),"dd-
mm-yyyy"),)]
ComboBox1.List = [index(date(year(today()),month(today())-
1,0)+row(offset(A1,,,day(date(year(today()),month(today()),0)),1)),)]
ComboBox1.List = [index(text(date(year(today()),month(today())-
1,0)+row(offset(A1,,,day(date(year(today()),month(today()),0)),1)),"dd-mm-yyyy"),)]
ComboBox1.List =
[index(date(year(today()),month(today())+1,0)+row(offset(A1,,,day(date(year(today()),month(today())+2,0)),1)),)]
ComboBox1.List =
[index(text(date(year(today()),month(today())+1,0)+row(offset(A1,,,day(date(year(today()),month(today())+2,0)),1)),"dd-
mm-yyyy"),)]
ComboBox1.List = [index(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+row(1:365),)]
ComboBox1.List = [index(text(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+row(1:365),"dd-mm-
yyyy"),)]
ComboBox1.List = [index(date(year(today())-1,1,4)-weekday(date(year(today())-1,1,4),2)+row(1:365),)]
ComboBox1.List = [index(text(date(year(today())-1,1,4)-weekday(date(year(today())-1,1,4),2)+row(1:365),"dd-mm-
yyyy"),)]
ComboBox1.List = [index(date(year(today())+1,1,4)-weekday(date(year(today())+1,1,4),2)+row(1:365),)]
ComboBox1.List = [index(text(date(year(today())+1,1,4)-weekday(date(year(today())+1,1,4),2)+row(1:365),"dd-mm-
yyyy"),)]
ComboBox1.List = [index(today()-29+row(1:28),)]
ComboBox1.List = [index(text(today()-29+row(1:28),"dd-mm-yyyy"),)]
ComboBox1.List = [index(today()+row(1:28),)]
ComboBox1.List = [index(text(today()+row(1:28),"dd-mm-yyyy"),)]
13 of 15 19/Nov-17, 11:02
VBA for smarties How to fill a Combobox / Listbox http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html
ComboBox1.List = [index(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+7*(row(1:53)-1),)]
ComboBox1.List = [index(text(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+7*(row(1:53)-1),"dd-mm-
yyyy"),)]
ComboBox1.List = [index(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+1+7*(row(1:53)-1),)]
ComboBox1.List = [index(text(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+1+7*(row(1:53)-1),"dd-
mm-yyyy"),)]
ComboBox1.List = [index(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+2+7*(row(1:53)-1),)]
ComboBox1.List = [index(text(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+2+7*(row(1:53)-1),"dd-
mm-yyyy"),)]
ComboBox1.List = [index(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+3+7*(row(1:53)-1),)]
ComboBox1.List = [index(text(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+3+7*(row(1:53)-1),"dd-
mm-yyyy"),)]
ComboBox1.List = [index(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+4+7*(row(1:53)-1),)]
ComboBox1.List = [index(text(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+4+7*(row(1:53)-1),"dd-
mm-yyyy"),)]
ComboBox1.List = [index(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+5+7*(row(1:53)-1),)]
ComboBox1.List = [index(text(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+5+7*(row(1:53)-1),"dd-
mm-yyyy"),)]
ComboBox1.List = [index(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+6+7*(row(1:53)-1),)]
ComboBox1.List = [index(text(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+6+7*(row(1:53)-1),"dd-
mm-yyyy"),)]
ComboBox1.List = [index(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+3+42*row(1:9),)]
ComboBox1.List = [index(text(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+3+42*row(1:9),"dd-mm-
yyyy"),)]
ComboBox1.List = [transpose(text(date(year(today()),1,4)-weekday(date(year(today()),1,4),2)+3+42*row(1:9),"dd-
mm-yyyy"))]
5.5 times
ComboBox1.List = [index(Text((row(1:24)-1)/24,"hh:mm"),)]
ComboBox1.List = [transpose(Text((row(1:24)-1)/24,"hh:mm"))]
ComboBox1.List = [index(Text((row(1:48)-1)/48,"hh:mm"),)]
ComboBox1.List = [transpose(Text((row(1:48)-1)/48,"hh:mm"))]
14 of 15 19/Nov-17, 11:02
VBA for smarties How to fill a Combobox / Listbox http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html
ComboBox1.List = [index(Text((row(1:96)-1)/96,"hh:mm"),)]
ComboBox1.List = [transpose(Text((row(1:96)-1)/96,"hh:mm"))]
ComboBox1.List = [index(Text((row(1:144)-1)/144,"hh:mm"),)]
ComboBox1.List = [transpose(Text((row(1:144)-1)/144,"hh:mm"))]
ComboBox1.List = [index(Text(row(8:18)/24,"hh:mm"),)]
ComboBox1.List = [transpose(Text(row(8:18)/24,"hh:mm"))]
ComboBox1.List = [index(Text(row(7272:7284)/8640,"hh:mm:ss"),)]
ComboBox1.List = [transpose(row(7272:7284)/8640,"hh:mm:ss"))]
5.6 Math
ComboBox1.List = [index(2^row(1:20),)]
ComboBox1.List = [index(Row(1:20)^2,)]
ComboBox1.List = [index(64^1/row(1:5),)]
15 of 15 19/Nov-17, 11:02