Trying to take data from a listbox to a textbox. Can somebody help with my code below.

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
Sub ListBox1_Click()

Dim Listbox1 As ListBox
Dim Textbox1 As TextBox



If Listbox1.ListIndex <> -1 Then


.Textbox1 = Listbox1.List(Listbox1.ListIndex, 9)

End With

End If

End Sub
 
From my understand you would have to refer to what column and what value in that column
This script would mean column 1 value 6 in that column
VBA Code:
Private Sub CommandButton2_Click()
'Modified  11/25/2020  10:27:12 AM  EST
ListBox1.ColumnCount = 10
TextBox1.Value = ListBox1.List(5, 0)
End Sub
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
When you get the error what gets highlighted in blue?
 
Upvote 0
Is that code in the userform module?
If so it means that you don't have a ListBox called ListBox1
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
I'm just trying to learn something also. Can you show me what script worked for you.
Private Sub ListBox1_Click()

If ListBox1.ListIndex <> -1 Then

TextBox1 = ListBox1.List(ListBox1.ListIndex, 8)
TextBox2 = ListBox1.List(ListBox1.ListIndex, 9)
TextBox3 = ListBox1.List(ListBox1.ListIndex, 4)
TextBox4 = ListBox1.List(ListBox1.ListIndex, 2)

End If

End Sub
 
Upvote 0
Private Sub ListBox1_Click()

If ListBox1.ListIndex <> -1 Then

TextBox1 = ListBox1.List(ListBox1.ListIndex, 8)
TextBox2 = ListBox1.List(ListBox1.ListIndex, 9)
TextBox3 = ListBox1.List(ListBox1.ListIndex, 4)
TextBox4 = ListBox1.List(ListBox1.ListIndex, 2)

End If

End Sub
Ok I see now how it works. Thanks
 
Upvote 0

Forum statistics

Threads
1,215,634
Messages
6,125,934
Members
449,275
Latest member
jacob_mcbride

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top