Confused about the ListBoxes.

F

fishonspeed

I have two list boxes that should both show the exact same thing. So I used
the exact same code for both boxes just with different variables that have
the exact same values.

The problem is that only the first list box shows anything. And even if I
take the code for ListBox1 out and leave everything for ListBox2 in the
selections still show up in ListBox1. If I have the code for both boxes
written, the selections still only show in ListBox1 and ListBox2 is blank.

Any ideas as to why this may be happening?
 
P

Per Jessen

Hi

Showing the code used to populate the list boxes will enable us to see what
is happening.

Regards,
Per
 
F

fishonspeed

Ah. That is true.
Here it is:

With Me.ListBox1
For ScreenCounter = 1 To .ListCount
If .Selected(ScreenCounter - 1) Then
ScreenTracker = ScreenTracker + 1
mySheetNames(ScreenTracker) = .List(ScreenCounter - 1)
Sheet(ScreenCounter) = mySheetNames(ScreenTracker)
End If
Next ScreenCounter
End With

With Me.ListBox2
For ScreenCounter2 = 1 To .ListCount
If .Selected(ScreenCounter2 - 1) Then
ScreenTracker2 = ScreenTracker2 + 1
mySheetNames2(ScreenTracker2) = .List(ScreenCounter2 - 1)
Sheet2(ScreenCounter2) = mySheetNames2(ScreenTracker2)
MsgBox (ScreenCounter2 & ScreenTracker2)
End If
Next ScreenCounter2
End With



--
I dispise your poor English and inability to use punctuation correctly ...
or at all.
~FishOnSpeed


Per Jessen said:
Hi

Showing the code used to populate the list boxes will enable us to see what
is happening.

Regards,
Per
 
P

Per Jessen

Hi again

I'm not sure what you are trying to to with this code part. What are the
variables refering to ?

Regards,
Per
 
F

fishonspeed

Their counting the sheets and placing the sheet names in a list that is then
displayed in a list box. I'm just confused as to why one works while the
other doesn't. The second one doesn't even execute. I've tried placing
MsgBoxes in several places throughout the second procedure and nothing
happens. The program completely skips that chunk of code.

I dispise your poor English and inability to use punctuation correctly ...
or at all.
~FishOnSpeed
 
P

Per Jessen

Okay, I don't see that your code is adding anything to the list boxes. Are
you sure that it's the code that populates Listbox1?

If you are working with a UserForm use the code below to populate the list
boxes with sheet names. If your list boxes is on a worksheet you can not use
Sub UserForm_Initialize, but the code within the sub will work.

Private Sub UserForm_Initialize()
For sh = 1 To ThisWorkbook.Sheets.Count
Me.ListBox1.AddItem Sheets(sh).Name
Me.ListBox2.AddItem Sheets(sh).Name
Next
End Sub

Best regards,
Per
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top