ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using arrays to create Combobox items (https://www.excelbanter.com/excel-programming/336947-using-arrays-create-combobox-items.html)

Mats Samson

Using arrays to create Combobox items
 
Hello out there!
I want to use the same items several times in different comboboxes, i.e.
a currency selection (EUR, USD, SEK, DKK......). There are 7 instances where
the user selects the currency to use (and it can be different currency at
every selection). Instead of reading the list from a sheet or writing the
same ComboboX.AddItem= "EUR" and so on for every new combobox, I wanted to
use an array and a for...next loop that can be used for every combobox
creation. But, arrays are not allowed in for...next statements.
Can it be done in another neat way?
Best regards
Mats

Dick Kusleika[_4_]

Using arrays to create Combobox items
 
Mats

You can assign an array directly to the List property, so no need for
For/Next.

Dim vaCurrency As Variant

vaCurrency = Array("EUR", "USD", "SEK", "DKK")

Me.ComboBox1.List = vaCurrency

Make vaCurrency a global variable and you can use it wherever you want.

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

Mats Samson wrote:
Hello out there!
I want to use the same items several times in different comboboxes,
i.e.
a currency selection (EUR, USD, SEK, DKK......). There are 7
instances where the user selects the currency to use (and it can be
different currency at every selection). Instead of reading the list
from a sheet or writing the same ComboboX.AddItem= "EUR" and so on
for every new combobox, I wanted to use an array and a for...next
loop that can be used for every combobox creation. But, arrays are
not allowed in for...next statements.
Can it be done in another neat way?
Best regards
Mats




Mats Samson

Using arrays to create Combobox items
 
Thanks Dick!
It helped and was as simple and neat as you could ask for!
Best regards
Mats

"Dick Kusleika" wrote:

Mats

You can assign an array directly to the List property, so no need for
For/Next.

Dim vaCurrency As Variant

vaCurrency = Array("EUR", "USD", "SEK", "DKK")

Me.ComboBox1.List = vaCurrency

Make vaCurrency a global variable and you can use it wherever you want.

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

Mats Samson wrote:
Hello out there!
I want to use the same items several times in different comboboxes,
i.e.
a currency selection (EUR, USD, SEK, DKK......). There are 7
instances where the user selects the currency to use (and it can be
different currency at every selection). Instead of reading the list
from a sheet or writing the same ComboboX.AddItem= "EUR" and so on
for every new combobox, I wanted to use an array and a for...next
loop that can be used for every combobox creation. But, arrays are
not allowed in for...next statements.
Can it be done in another neat way?
Best regards
Mats






All times are GMT +1. The time now is 05:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com