problem with userform listbox

paulsolar

Well-known Member
Joined
Aug 21, 2013
Messages
682
Office Version
  1. 365
Hi All

I'm trying to populate listbox2 in a userform depending on the selection in listbox1

I've been going around in circles with this for a while without getting anywhere

below is what I have been trying

I have tried a few different methods without any luck

Any suggestions would be greatly appreciated

cheers

Paul

VBA Code:
Private Sub ListBox1_Click()
  
    If ListBox1.ListIndex = -1 Then
        
        ListBox2.Clear
        
    Else
    
    If ListBox1.ListIndex = 0 Then
    
        ListBox2.List = Sheet4.Range("K1:K43") 'this is a names range singlesingle
        
    Else
    
     If ListBox1.ListIndex = 1 Then
        ListBox2.List = Sheet4.Range("O1:O35") 'this is a names range doublesingle
        
    Else
    
     If ListBox1.ListIndex = 2 Then
        ListBox2.List = Sheet4.Range("S1:S43") 'this is a names range doubledouble
        
    End If
    End If
    End If
    End If

End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hello Paul, try adding .value to the ranges like
VBA Code:
Listbox2.List = Sheet4.Range("K1:K43").Value
 
Upvote 0
Try this.
VBA Code:
Option Explicit

Private Sub ListBox1_Click()

    Select Case ListBox1.ListIndex
        Case -1
            ListBox2.Clear
        Case 0
            ListBox2.List = Sheet4.Range("K1:K43").Value    'this is a names range singlesingle
        Case 1
            ListBox2.List = Sheet4.Range("O1:O35").Value    'this is a names range doublesingle
        Case 2
            ListBox2.List = Sheet4.Range("S1:S43").Value    'this is a names range doubledouble
    End Select

End Sub
 
Upvote 0
Try this.
VBA Code:
Option Explicit

Private Sub ListBox1_Click()

    Select Case ListBox1.ListIndex
        Case -1
            ListBox2.Clear
        Case 0
            ListBox2.List = Sheet4.Range("K1:K43").Value    'this is a names range singlesingle
        Case 1
            ListBox2.List = Sheet4.Range("O1:O35").Value    'this is a names range doublesingle
        Case 2
            ListBox2.List = Sheet4.Range("S1:S43").Value    'this is a names range doubledouble
    End Select

End Sub
Thanks both, worked first time, I tried everything bar that

cheers

Paul
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

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