PDA

View Full Version : vba excel populate textbox into listbox



Kaniguan1969
02-20-2014, 07:08 AM
Hi,

I have a userform with textboxes and combox. composed of 10 txtbox and 2 combobox.
I would like to insert the data from textboxes and combobox to listbox for the user to double check the entry before
saving to workbook. this could be a multiple rows of data in listbox.

Initial appearance of listbox from userform is empty until the user click the posting button, transaction will happen the listbox will have a data. listbox will be clear after the user finish the transaction. basically, per ticket number will be multiple transaction.

Thank you very much!

attached sample screenshot

Jomathr
02-20-2014, 02:26 PM
Hello Kaniguan,

you will probably want to use something like this in the button you click to add it to listbox:



Dim x As Integer
x = LstBox.ListCount

With LstBox
.AddItem
.List(x, 0) = TxtBox1.Value
.List(x, 1) = TxtBox1.Value
.List(x, 2) = TxtBox1.Value
.List(x, 3) = TxtBox1.Value
.List(x, 4) = ComboBox1.Column(1) 'In case you are using multicolumn combobox
.List(x, 5) = ComboBox1.Column(2) 'In case you are using multicolumn combobox
.List(x, 6) = ComboBox2.Value
end with


and on your save button you will want:



LstBox.clear


Hope it helped!

Kaniguan1969
02-21-2014, 06:56 AM
Thank you very much for your reply Jomathr.
another thing how could I put a column header in listbox? as you can see in my sample it is an empty listbox.
can i add that when opening the userform_initialize?

btw, I've read from other column that listbox is a good choice for beginner like me. actually i tried listview but got an error and i have a hard time to fixed.
a lot of times i consume surfing the net to get samples of list view.

anyway, what is the difference of listview ver 5 and listview ver 6?

Jomathr
02-21-2014, 07:52 AM
The only way to put headers on your listbox is to add labels since listbox will only allow you to use headers if tou use the rowsource property.

About the listview, it's an object that is used in other languages such as VB and is more flexible with less limitations then listbox, but also a bit trickier to work with at first. But I don't know what are the major differences between the 2 versions sorry.

Glad I could help! Have a nice one!