VBA List Box Question

christianbiker

Active Member
Joined
Feb 3, 2006
Messages
365
Hi All,

I have this code that I have pulled from "VBA and Macros for Microsoft Excel" and it works in the context that it is supposed to, however I do have a question.

Private Sub CommandButton1_Click()

Dim lastrow As Long, i As Integer
lastrow = Worksheets("Sheet1").Range("A65536").End(xlUp).Row + 1
Cells(lastrow, 1).Value = TextBox1.Value
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
Cells(lastrow, 2).Value = Cells(lastrow, 2).Value & _
ListBox1.List(i) & ", "
End If
Next i
Cells(lastrow, 3).Value = TextBox2

End Sub

My question is this...

Rather than have all of the selected items placed in one cell, separated by a comma, can I actually have each item placed in it's own separate cell, preferably in list format or horizontally if not?

Thanks!
 
Sorry...I am not sure why my one post kept posting itself. I did have some problems with the site for a bit.

I am not really sure how to explain this in a way that is understandable...

I will be using optionbuttons, textboxes and listboxes to enter in the specified information. By looking at the very beginning of this post you can see that I am using both the textbx function and the listbox function. Regardless of the row I am on you will see that in column 1 it will show the text entered on the userform into textbox1. In column 2 you will see the selections from the listbox entered and separated by commas. You will then see that in column 3 and on the same line, the text from the userform as entered in textbox2 I believe.

That is the same format I would like to use with your format, which I did figure out for the vertical entries of the listbox, but am unsure how to do the horizontal entries from the listbox and making any entries via a textbox after the listbox be entered in after the final entry from the listbox.

Clear as mud right? Probably not but I hope you can decipher what I am trying to say!

Thanks again!
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,215,457
Messages
6,124,941
Members
449,197
Latest member
k_bs

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