VBA USERFORM : Combobox Droplist concatenation

sachinns

Board Regular
Joined
Jun 21, 2019
Messages
52
Hi Friends,

Example : www.imgur.com/2lAUMdM


Please see this image as example. I have a combobox called "cmbpivotvalue" in my Userform. I want " A1,A2,A3,A4,B1,B2,B3,B4,C1,C2,C3,C4 " as values in my combobox dropdown (Refer the example) . Basically I want the heading name + values under that corresponding heading.
The values are taking from the sheet called "Inconsistency" .
Someone please me to add this condition into my existing code . I hope you are clear with my definition.

Code:
Function formInitialize(ws As Worksheet)
Dim n
Dim cell As Range
Dim pivotvaule As String

Set ws = ThisWorkbook.Worksheets("Inconsistency")
If ws.Visible = True Then
    ws.Activate
Else
    ws.Visible = xlSheetVisible
    ws.Activate
End If


n = 38
For n = n + 1 To 100
    pivotvaule = Cells(8, n).Value
    Me.cmbpivotvalue.AddItem pivotvaule
    pivotvaule = ""
    Me.Label3.Visible = False
    Me.lsbOrderSet4SelAttr.Visible = False
Next n
End Function
 
Last edited:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi Friends,

Example : www.imgur.com/2lAUMdM


Please see this image as example. I have a combobox called "cmbpivotvalue" in my Userform. I want " A1,A2,A3,A4,B1,B2,B3,B4,C1,C2,C3,C4 " as values in my combobox dropdown (Refer the example) . Basically I want the heading name + values under that corresponding heading.
The values are taking from the sheet called "Inconsistency" .
Someone please me to add this condition into my existing code . I hope you are clear with my definition.

Maybe you need a listbox.
In a listbox you can put headers and the data of each header.





0bfc378f159c0fcc6d65156e3f89d1ed.jpg


Use the properties on Listbox1:
ColumnCount 4
ColumnHeads True
RowSource range


For example:

Code:
Private Sub UserForm_Activate()
    With ListBox1
        .ColumnCount = 4
        .ColumnHeads = True
        .RowSource = "A2:C10"       'In cells A1:C1 should be the headers
    End With
End Sub
 
Upvote 0
Thanks for the response. But this is not i want.

My actual data sheet is too complex and big. So i will explain in a simpler way.

I have some main headings in my column. for example : we will take "mobile Brands".

My column heading is Apple , sony , Samsung. And we have sub columns price , colour and year for all these 3 brands.
So in my droplist i need : apple price , appe colour , apple year , sony price , sony colour , sony year , samsung price , samsung colour , samsung year.


I hope now it is clear.

Sheet Download : https://filebin.net/hmzl7ezugdqsmpy8

OR

http://www.fast-files.com/getfile.aspx?file=202201Sample.zip
 
Upvote 0
For security reasons it is not possible to download .zip files. unless you put an excel file in dropbox.

I guess your data is this way:

3834086cee15d5d8bcab7ebf23e9ae76.jpg


Try this code:

Code:
Private Sub UserForm_Activate()
    Dim j As Long, t1 As String, t2 As String
    For j = 1 To Cells(2, Columns.Count).End(xlToLeft).Column
        If Cells(1, j).MergeCells Then
            t1 = Cells(1, j).MergeArea.Cells(1, 1).Value
            t2 = Cells(2, j).Value
        Else
            t1 = Cells(1, j).Value
            t2 = Cells(2, j).Value
        End If
        ComboBox1.AddItem t1 & " " & t2
    Next
End Sub
 
Upvote 0
Cross posted http://www.vbforums.com/showthread....t-concatenation-Help-!!&p=5399555#post5399555

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,214,938
Messages
6,122,346
Members
449,080
Latest member
Armadillos

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