Manipulating a ListBox

musoguy

Board Regular
Joined
May 20, 2008
Messages
173
In the thread: http://www.mrexcel.com/forum/showthread.php?p=1923351#post1923351 Norie wrote:

Originally Posted by Norie

Have you considered using a listbox?

Perhaps in combination with a combobox, textbox and command button.

User select makes selection from combobox,textbox etc hit's the command
button (or presses Enter if it's Default property is set to Yes), data added to listbox, other controls cleared...

Then once the user is done they can review what they've chosen in the listbox and with another command button commit it to a worksheet(s).

This could be further enhanced by adding other controls to add/delete/alter etc

If you post back with more specific details and some sample data/results I'm sure we will be able to give more specific help.
This happens to be exactly what I am trying to create right down to the add/delete/alter buttons at the moment! I've tried searching for a clue on how to add multiple lines of text that I create from a TextBox one at a time to a listbox, but haven't had any luck. I also don't know where to start with altering/adding or removing the text once it is in the ListBox, and in indeed how to then copy each line to a column in the workbook. So everything really! Any help would be much appreciated :)

James
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
James

Here's a very simple start.

1 Create a useform.

2 Add a textbox, a listbox and a command button.

3 Add this code.
Code:
Option Explicit
 
Private Sub CommandButton1_Click()
    With TextBox1
        ListBox1.AddItem .Value
        .Value = ""
        .SetFocus
    End With
End Sub

Like I said basic, doesn't check data, doesn't store data on worksheet, doesn't delete etc. just adds what's in the textbox to the listbox.

If you add another button you could use this to remove the selected item from the listbox.
Code:
Private Sub CommandButton2_Click()
    If ListBox1.ListIndex <> -1 Then
        ListBox1.RemoveItem ListBox1.ListIndex
    End If
End Sub
To be more specific we would need more details.

By the way have you tried the built-in form, Data>Form...?
 
Upvote 0
Thanks for the reply Norie. That's great to get me started. I'll let you know how I get on, and be more specific if there is something I can't figure out. Thanks again

I haven't used the built in form before. They seem to have done everything in their power to make it impossible to find in Excel 2007! I even tried following the help instructions to locate it, but couldn't! As it happens, the ListBox you have helped my create is part of a larger macro that runs before and after, and being able to call on a floating ListBox is better for me.

Thanks again for your help Norie, really appreciate you taking the time :)

James
 
Upvote 0
James

2007? Tried a trial - it failed.:)

Anyway here's a link that tells you how to get the built-in form.

But it also has information/links that might be of interest.
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,212
Members
448,874
Latest member
b1step2far

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