Multiple worksheet for combobox

hedgehog88

New Member
Joined
Mar 25, 2011
Messages
6
Another question.

I have this Initialize sub for a userform which I would like to have it set for multiple worksheets (not workbook). And have the combobox populate from another worksheet range.

My code right now for one worksheet is:

Private Sub UserForm_Initialize()

Dim cLoc As Range
Dim ws As Worksheet
Set ws = Worksheets("LookupList")

Is there a way to add another worksheet, such as LookupList2?

Thanks in advance
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Sorry, but that code isn't populating a combobox from any worksheet.

Is it definitely all the code?
 
Upvote 0
Sorry, but that code isn't populating a combobox from any worksheet.

Is it definitely all the code?

It does work.

Private Sub UserForm_Initialize()

Dim cLoc As Range
Dim ws As Worksheet
Set ws = Worksheets("LookupList") <-----

For Each cLoc In ws.Range("AlertType")
With Me.cboAlertType
.AddItem cLoc.Value
End With
Next cLoc

However it only grabs the list range from "Lookuplist" worksheet. I would to know if its possible to add another worksheet so my combobox can list that worksheet range list as well.

I used codes from: http://www.contextures.com/Excel-VBA-ComboBox-Lists.html
 
Last edited:
Upvote 0
Well, that code does populate the combobox.:)

If you just want to add the items from the other worksheet after the ones you are adding already just duplicate the code and change the worksheet/range name.
Code:
For Each cLoc In ws.Range("AlertType")

   With Me.cboAlertType
      .AddItem cLoc.Value
   End With

Next cLoc
 
Set ws = Worksheets("OtherWorksheet")
 
For Each cLoc In ws.Range("OtherRange")
 
    With Me.cboAlertType
        .AddItem cLoc.Value
    End With
 
Next cLoc
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,144
Members
448,552
Latest member
WORKINGWITHNOLEADER

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