• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 170
  • Last Modified:

Combobox Rowsource with Dynamic Named Ranges VBA Excel

Hello Experts,

Please kindly Guide me that i can Combox2 in which i want add items with Change in Combox1 i have Dynamic Name ranges using Offser Through Formula Name Manager Range1,Range2,Range3,Range4 all Ranges have Multiple Rows to Add i have too add all ranges items  in combox2 so i made code

userform1.combobox2.rowsource = "Range1" Its Working but when i want to Put Multiple named ranges like this userform1.combobox2.rowsource = "Range1","Range2","Range3","Range4" Please guide me is it possible to load items from multiple named ranges if possible then kindly advice solution.

if not then what is alternate solution.

Regards
0
WiseOwl Excel
Asked:
WiseOwl Excel
1 Solution
 
Ejgil HedegaardCommented:
Rowsource can only use a single column.

You can do something like this, if the ranges are the same size.
Option Explicit

Private Sub UserForm_Initialize()
    Dim cl As Range, i As Integer
    
    Me.ComboBox1.ColumnCount = 3
    Me.ComboBox1.ColumnWidths = "20,20,20"
    
    For Each cl In [Range1]
        Me.ComboBox1.AddItem cl.Text
    Next cl
    
    i = 0
    For Each cl In [Range2]
        Me.ComboBox1.Column(1, i) = cl.Text
        i = i + 1
    Next cl
    
    i = 0
    For Each cl In [Range3]
        Me.ComboBox1.Column(2, i) = cl.Text
        i = i + 1
    Next cl
End Sub

Open in new window

0
 
NorieVBA ExpertCommented:
Is the combobox multicolumn and you want to populate each column from one of the named ranges?

Or is it single column and you want to populate it with values from all the named ranges one above the other?
0
 
WiseOwl ExcelAuthor Commented:
@Norie,

I want to Populate in Single Column From My Named Ranges and Not My Name Ranges have onliy one Column.

Regards
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
NorieVBA ExpertCommented:
You wouldn't be able to do that using RowSource, you would have to use AddItem or List.
Dim rng As Range
Dim ar As Range
Dim cl As Range

    Set rng = Range("Range1, Range2, Range3")
    
    For Each ar In rng.Areas
        For Each cl In ar.Cells
            ComboBox1.AddItem cl.Value
        Next cl
    Next ar

Open in new window

0
 
WiseOwl ExcelAuthor Commented:
rng = Range("Range1, Range2, Range3")

Syntex Error How Ever i have done it with with.

Thanks for Your Kind Input.

Regards,
0
 
Rob HensonFinance AnalystCommented:
It is also possible with Data Validation.

Take a look at this article: Dynamic Data Vaildation

Any queries from that, please comment on the article.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now