PDA

View Full Version : [SOLVED:] array filling with multiple unique names



wannabe11
10-05-2017, 10:46 AM
hello guys

i'm looking for a solution , basically i want to fill an array with 200 different names NAME1,NAME2,NAME200

i know for sure there is a method to avoid doing this manually (array(1)=NAME1 array(2)=NAME2) .

and yes i searched within the forum or the internet and i couldnt find the answer i'm looking for .

i read about combo/box/list and i dont know if its the solution to my problem . if so is it the only solution ? and how do we actually make a combo list and fill it ?

also i read about the split function for arrays but from what i understood its not what i'm looking for .

thanks in advance for your help .

Kenneth Hobs
10-05-2017, 11:25 AM
I am not sure where your unique issue comes into play. String concatenation would be one way to fill an array. An array can be used to fill a listbox or combobox control using their List property.

e.g. Using an activex combobox on Sheet1.

Sub Main()
Dim a(1 To 20), i As Integer
For i = 1 To 20
a(i) = "NAME" & i
Next i
MsgBox Join(a, vbLf)
Sheet1.ComboBox1.List = a
End Sub

mdmackillop
10-05-2017, 11:26 AM
Sub Test()
Dim arr(1 To 200)
For i = 1 To 200
arr(i) = "NAME" & i
Next


'Test
Cells(1, 1).Resize(200) = Application.Transpose(arr)
End Sub

wannabe11
10-05-2017, 11:41 AM
thanks for your time guys , the solution works fine .

also thanks for including tests its always useful .

snb
10-05-2017, 01:43 PM
Sub M_snb()
listbox1.list=sheets(1).range("A1:A200").value
End Sub

More on populating: http://www.snb-vba.eu/VBA_Fill_combobox_listbox_en.html

wannabe11
10-11-2017, 08:59 AM
Thanks for your answer , thats the actual link where i read about combobox/listbox before posting on here .