Populate list using worksheet references

lukecthomas

New Member
Joined
Nov 21, 2008
Messages
2
I have a form with five option buttons and a list box. When each one is selected it is suppose to give a list of accounts depending on the button selected. The lists are derived from a worksheet that lists hundreds of numbered accounts. I've made two loops that find the beginning and ending rows for each category. From here I'm trying to take those row cell references and put everything in between in a list when one of the option buttons is clicked. I'm guessing I need a with statement and a for loop inside, but 'm not quite sure about all the syntax with lists. Please Help.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi and Welcome to the Board,

Below is an example that shows a syntax for populating lists from a range.
Rich (BB code):
Public Function Popluate_List(lCategory As Long)
    Dim rListRange As Range
    '---your code to set rListRange based on lCategory
    '---option button selected, for example...

    With Sheets("Sheet1")
        Select Case lCategory
            Case 1
                Set rListRange = .Range("A201:A300")
            Case 2
                Set rListRange = .Range("A301:A400")
               '----continue for all options
        End Select
    End With

    '----clear and populate listbox
    With UserForm1.Listbox1
        .Clear
        .List = rListRange.Value
    End With
End Function

Call the function with your OptionButton Click events
Rich (BB code):
Private Sub OptionButton1_Click()
    Popluate_List (1)
End Sub
Private Sub OptionButton2_Click()
    Popluate_List (2)
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

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