-
Solved: Bonus question
Hi Again !
This is a continuation of the "Make a structured list in a textbox. " thread.
I have a bonus question. I have integrated the listbox system into my Server program , but i would like the listbox2 servers to be stored in an array rather than as a string.
This is probably very simple for the most of you , but it would help me immensly (and make me look like an expert to my boss).
here is a bit of code.
[VBA]
UserForm2.ListBox1.List = colsarray()
UserForm2.Show vbModal
Textstring = ""
For counter = 1 To UserForm2.ListBox2.ListCount
Textstring = Textstring + UserForm2.ListBox2.List(counter - 1) & vbCrLf
ServerList(counter) = UserForm2.ListBox2.List(counter - 1) '*******
Next
[/VBA]
The row marked by "*" is the one i am having trouble with...
thanks !
-
[vba]
With UserForm2
.ListBox1.List = colsarray()
.Show vbModal
Textstring = ""
ReDim colsarray(1 To 1)
For counter = 1 To .ListBox2.ListCount
Textstring = Textstring + .ListBox2.List(counter - 1) & vbCrLf
ReDim Preserve ServerList(1 To counter)
ServerList(counter) = .ListBox2.List(counter - 1)
Next
End With
[/vba]
-
I've tweaked my eample a little to upload sample code
[VBA]
Option Explicit
Private Sub CommandButton1_Click()
Dim serverlist, s, Textstring As String, Counter As Long
UserForm2.ListBox2.List = (Range("colsarray"))
Textstring = ""
ReDim serverlist(UserForm2.ListBox2.ListCount)
For Counter = 1 To UserForm2.ListBox2.ListCount
Textstring = Textstring + UserForm2.ListBox2.List(Counter - 1) & vbCrLf
serverlist(Counter) = UserForm2.ListBox2.List(Counter - 1)
Next
For Each s In serverlist
Debug.Print s
Next
End Sub
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
Thank you both for your efforts ! I managed to make it work just before my coffe break
Thanks yet again !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules