Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate ComboBox with Named Range

Status
Not open for further replies.

inkserious

Technical User
Jul 26, 2006
67
I'm trying to populate a ComboBox with a named range. For example, I have a named range called currentMonth. This range contains the name of a month. I have named ranges for all of the months. So if currentMonth contains October, then the ComboBox would be populated with the named range October.

I can hardcode the month, but I can't seem to figure out how to take the string value in the currentMonth named range and convert it to the respective range. Thanks in advance for any help anyone can provide.

Code:
Private Sub setMonth()
 
Dim ws As Worksheet
Dim cDate As Range
 
    Set ws = Worksheets("ranges")
        For Each cDate In ws.Range("October")
             With Me.cboDate
            .AddItem cDate.Value
        End With
    Next cDate
 
End Sub
 
My apologies the variable is curDate, not cDate.

Thanks again.
 
Figured it out!

Code:
Private Sub setMonth()
 
Dim ws As Worksheet
Dim cMonth As String
Dim myMonth As Range
Dim curDate As Range
 
    Set ws = Worksheets("ranges")
    cMonth = ws.Range("currentMonth")
    Set myMonth = Range(cMonth)

        For Each curDate In myMonth
            With Me.cboDate
                .AddItem curDate.Value
        End With
    Next curDate
 
End Sub
 

hi,
Code:
   cboDate.listfillrange = "currentMonth"

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top