• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

ListBox1_Click(How to simplify code)

S P P

Member
ListBox1_Click(How to simplify code)
I use it like this
>>> as You've noted <<<
>>> use code - tags <<<

Code:
Private Sub ListBox1_Click()
I have more than 9 textboxes
TextBox1 = ListBox1.List(ListBox1.ListIndex, 0) '1ª COLUMN
TextBox2 = ListBox1.List(ListBox1.ListIndex, 1) '2ª COLUMN
TextBox3 = ListBox1.List(ListBox1.ListIndex, 2) '3ª COLUMN

TextBox10 = ListBox1.List(ListBox1.ListIndex, 9) '10ª COLUMN
TextBox11 = ListBox1.List(ListBox1.ListIndex, 10) '11ª COLUMN
End Sub

'How to simplify
Private Sub ListBox1_Click()
'You can change it to greater than 9
 For K = 0 To 9
       Me("Textbox" & K) = ListBox1.Column(K)
Next
End Sub
 
Last edited by a moderator:
Code:
Private Sub LB_00_Click()
For i = 0 To 9
    Me("T_0" & i) = LB_00.Column(i)
Next
For i = 10 To 11
    Me("T_" & i) = LB_00.Column(i)
Next
End Sub
Give your texxboxes, simple names like T_00 , T_01 and so on
In this example the listbox is named LB_00
 
Back
Top