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
 
What is the name of the listbox?
Also is it on a sheet or userform?
What is the name of the listbox? Listbox1
Also is it on a sheet or userform? On a user form which is called "Body_And_Vehicle_Type"
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
In that case you you copy paste my code, or try adapting your code?
 
Upvote 0
The OP asked for the 9th column & if you look at the OP's code that is what he/she is trying to do.
The original post did not say column 9. He added that information in post 2 after I had written my code
 
Upvote 0
He added that over 15 minutes before you posted & there is still the matter of the original code which (IMO) makes perfectly clear that he is trying to get the value from column index 9
 
Upvote 0
In that case you you copy paste my code, or try adapting your code?
This is what i did but it won`t work. Now says "wrong number of arguments or invalid property assignment" Code below

Private Sub Listbox1_Click()

Dim ListBox1 As ListBox
Dim TextBox1 As Textbox

If ListBox1.ListIndex <> -1 Then

TextBox1 = ListBox1.List(ListBox1.ListIndex, 9)

End If

End Sub
 
Upvote 0
Delete that code & replace it with the code I suggested.
Also how many columns do you have in the listbox?
 
Upvote 0
I have tried this

The listbox1 first line says error "Variable not defined"

Sub ListBox1_Click()
If ListBox1.ListIndex <> -1 Then
TextBox1 = ListBox1.List(ListBox1.ListIndex, 9)
End If
End Sub

Columns in the listbox is 10
 
Upvote 0
Is your textbox called TextBox1
 
Upvote 0
FYI, if you want column 9, it will be ListBox1.List(ListBox1.ListIndex, 8) as and when you figure out the other issues. ;)
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,421
Members
448,961
Latest member
nzskater

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