Clickable listbox items

eliza6

New Member
Joined
Jul 14, 2011
Messages
11
Hi everybody. I need a help. I have a listbox with two items. There is an option to remove one item, or the other, and then the list is empty and you can re-add it again if you want. I need whenever items are back on the list, to be clickable. The problem is that each item has to open separate form. Item 1 has to open form 1, item 2 - open form 2. Any ideas? I am over my head.


ListBox1.Clear
ListBox1.AddItem Sheets("Data").Range("A1")
ListBox1.AddItem Sheets("Data").Range("A2")

For x = ListBox1.ListCount - 1 To 0 Step -1
If Trim(ListBox1.List(x)) = "" Then
ListBox1.RemoveItem x
End If
Next x


the code above, removes an item from the listbox when one of the cells is empty. as my items are populeted from cells.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Still need help with this. Thanks

maybe something like this :

Code:
Private Sub ListBox1_Click()

    If ListBox1.ListIndex = 0 Then
        UserForm1.Show  'first form
    Else
        UserForm2.Show  'second form
    End If

End Sub
 
Upvote 0
@Jaafar: works fine until you remove one of the items. then item what's left (no. 2 for example) opens up form 1 instead of form 2.
 
Upvote 0
@Jaafar: works fine until you remove one of the items. then item what's left (no. 2 for example) opens up form 1 instead of form 2.

What values do you have in cells A1 and A2 ? and do these values change or are they constants ?
 
Upvote 0
Why a listbox for just 2 items?

Couldn't you just use a couple of command buttons, or option buttons?

Maybe even a checkbox.
 
Upvote 0
@ Norie, Jaafar: What I am trying to do is make a training environment for one of the programs we use at work. I would like mine to look as similar to the original version as possible. Therefore I need listbox, not checkbox or buttons which would make the whole thing look different and very confusing for new starters who are trying to learn.

The values I have in the cells is text, like: Token 1, Token 2. When I remove the text from the cell, one of the items from the list disappears, just like I want to. At some point one of the buttons will change the token status, so the text in the cell will change, which should be reflected in the listbox. So I can say the values change and are not constant. I hope I explained myself correctly.
 
Upvote 0
You could easily change the captions of buttons, hide/show them etc.
 
Upvote 0
@Norie: That is not what I need.
I don't think I can do this with anything other than listbox (because it has to look like the image below)... but you be the judge

tokensj.jpg
 
Upvote 0
I thought you only had 2 items of data?

If you do have multiple items then yes a listbox would probably appropriate

If your 2 items actually consist of more than one value, then again a listbox might be appropriate.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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