How to Add an Item to a specific column to a ListBox using t

razzandy

Active Member
Joined
Jun 26, 2002
Messages
388
Office Version
  1. 2007
Platform
  1. Windows
I’ve managed to come up with the below code which adds the text from another combobox to the first column of the list box but I also want to add the text from another combobox to column 2 and so on. Can anybody help??

ListBox1.AddItem (ComboBox1.Text)

Thanks in advance

Cheers

Ryan UK
This message was edited by razzandy on 2002-10-16 11:23
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

ChrisUK

Well-known Member
Joined
Sep 3, 2002
Messages
675
You can use ListBoxName.AddItem "NewItem"

If you want to get the 'NewItem' from another ComboBox then:

ListBoxName.AddItem ComboBox.ListIndex(x) where x is the row number

HTH

Chris
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Have a look at the Column property of the ListBox object.

Syntax

object.Column( column, row ) [= Variant]

The Column property syntax has these parts:

Part Description
object Required. A valid object.
column Optional. An integer with a range from 0 to one less than the total number of columns.
row Optional. An integer with a range from 0 to one less than the total number of rows.
Variant Optional. Specifies a single value, a column of values, or a two-dimensional array to load into a ListBox or ComboBox.

Settings

If you specify both the column and row values, Column reads or writes a specific item.

The List property is similar.
 

razzandy

Active Member
Joined
Jun 26, 2002
Messages
388
Office Version
  1. 2007
Platform
  1. Windows
Thanks Chris but I think you've misunderstood me!

This code works fine:

Private Sub CommandButton_Click()
ListBox1.AddItem (ComboBox1.Text)
End Sub

It adds the text from the coboBox to the first row of the listbox and then continues down to the next row for every click.

What I want to do is specify the column in the listbox I want the text to go to!

Any more suggestions

Cheers

Ryan UK :)
 

ChrisUK

Well-known Member
Joined
Sep 3, 2002
Messages
675
you're right, it's late in the day and I need food!

I think Andrew has replied with whats needed now anyway.

Chris
 

razzandy

Active Member
Joined
Jun 26, 2002
Messages
388
Office Version
  1. 2007
Platform
  1. Windows
Cheers Andrew youe helped me yet again. :)

Here's what I've come up with thanks to u! As you can see I've renamed my ListBoxes & ComboBoxes.

Private Sub ProAddBtn_Click()
Dim ListCount As Single
ListCount = ProductLst.ListCount
ProductLst.AddItem
ProductLst.Column(7, ListCount) = ProdCom.Text
End Sub

Many Thanks

Ryan UK :wink:
 

Forum statistics

Threads
1,144,765
Messages
5,726,175
Members
422,660
Latest member
mrsteele

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
Top