ListBox won't respond

Bagharmin

Board Regular
Joined
Nov 22, 2010
Messages
168
I have two OptionButtons and two ListBoxes. When I click on OptionButton2, ListBox1 goes away and ListBox2 becomes visible and enabled. When I click OptionButton1, ListBox2 goes away and ListBox1 becomes visible and enabled and I set the ListIndex of ListBox1 to 0.

Private Sub OptionButton1_Change()
If OptionButton1.Value = True Then
With ActiveSheet
.ListBox2.Visible = False
.ListBox2.Enabled = False
.ListBox1.Visible = True
.ListBox1.Enabled = True
.ListBox1.ListIndex = 0
End With
Else
With ActiveSheet
.ListBox1.Visible = False
.ListBox1.Enabled = False
.ListBox2.Visible = True
.ListBox2.Enabled = True
.ListBox2.ListIndex = 0
End With
End If
End Sub

When I click in ListBox1, some other code is supposed to make a ComboBox visible and populate it if the user chooses a certain item in the ListBox or take the ComboBox away if they choose something else in the ListBox:

Private Sub ListBox1_Change()
Select Case ListBox1.ListIndex

Case 3

ActiveSheet.ComboBox2.Visible = True
ActiveSheet.ComboBox2.Enabled = True
If ActiveSheet.Range("O2").Value <> ActiveSheet.Range("O3").Value Then
Call LoadClients
End If

Case Else

ActiveSheet.ComboBox2.Visible = False
ActiveSheet.ComboBox2.Enabled = False

End Select
End Sub

My problem is this: When I go back to OptionButton1, I can't click in ListBox1 at all. I have to go back to OptionButton2, then back to OptionButton1 before I can choose any of the 4 entries in ListBox1. Obviously I don't want people who use this to have to do that every time. Can anyone tell me how to fix this?

Every other time that I go to OptionButton2, then back to OptionButton1, ListBox1 becomes unclickable.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I may have posted too late in the day yesterday. Does anyone have any suggestions as to why the ListBox1 works only every other time the code makes it visible?
 
Upvote 0
I did some further testing (using message boxes to show what had focus) and found the following:
  1. Clicked on OptionButton2 (with ListBox1 working) - ListBox1 lost focus and OptionButton2 got focus
  2. Clicked on OptionButton1 - OptionButton2 lost focus and OptionButton1 got it
  3. Clicked on ListBox1 - OptionButton1 lost focus, but ListBox1 didn't get it
  4. Clicked on OptionButton2 - OptionButton2 got focus, but nothing lost it
Any thoughts?
 
Upvote 0
I Know this is an OLD post but I am experiencing the same exact problem did you ever find a solution for this?
 
Upvote 0
Never did. I eventuall re-thought the whole thing and reorganized the option buttons and list boxes, leaving all of them visible all the time. Now the user makes his/her selections, but nothing happens until a "Run Report" button is clicked. Then the code looks at the various controls to see what options were selected and provides the appropriate results.

I've pretty much given up trying to be fancy and clever and have opted for brute-force coding. My spreadsheets/forms may have a few more controls on them, but it saves hassle in the long run.

If you find a solution, though, leave a reply as I'd LOVE to know what was going on.
 
Upvote 0
I actually have found a solution use the following commands to hide and unhide the boxes and it should work:

Private Sub ToggleButton1_Click()
If ToggleButton1 Then
Sheets("Matrix").ListBox2.Visible = True
Sheets("Matrix").CommandButton3.Visible = True
Else
Sheets("Matrix").ListBox2.Visible = False
Sheets("Matrix").CommandButton3.Visible = False
End If
End Sub
 
Upvote 0
I didn't have a problem making the controls visible and not-visible (that part worked fine). My problem was that, after switching back and forth, I would click on one of the list boxes, but nothing would happen. I would have to switch back and forth again before the list box would work. That's the issue for which I never found a true solution.
 
Upvote 0
that was the same issue I had, and when I changed the syntax of the commands to the style above that didn't happen anymore, I had a different syntax the first time and the boxes would hide and unhide but I couldn't click them. Once I changed to that they worked perfectly.
 
Upvote 0
Hmmm...

Then perhaps my problem was referring to ActiveSheet instead of naming the sheet I wanted. I may have to revisit that at some time.
 
Upvote 0
It might work its worth a shot, I was using the .shapes command previously and it would hide and unhide the listbox but i had the same issue that i couldn't click it anymore. Until i changed to the code mentioned above, which somebody suggested to me on this forum.
 
Upvote 0

Forum statistics

Threads
1,224,605
Messages
6,179,860
Members
452,948
Latest member
UsmanAli786

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