Combobox Sub Worksheet_Change(ByVal Target As Range)

ayazgreat

Well-known Member
Joined
Jan 19, 2008
Messages
1,151
hi All

I need help on the following

I have a combobox on sheet and I want it to fill when a value change on range b1 let me explain you

Sub Worksheet_Change(ByVal Target As Range)<strike></strike>

If range b1 a text A then combobox would fill with AA,BB,CC

If range b1 a text B then combobox would fill with DD,EE,FF

If range b1 a text C then combobox would fill with GG,HH,LL


Thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Is your combo box a form control or an active-x control? Do you have a list fill range on the sheet with the control? If yes, what is the range? If no, what range would you like to use to hold the list fill? What is the name of the combo box?
 
Last edited:
Upvote 0
So if Range("B1").value= "A" then you want ComboBox to look like this:

"AA"
"BBB"
"CC"

Is this what you want?

And what ComboBox?

Is it "Combobox1" or "ComboBox2"

You gave no details.
 
Upvote 0
it is combobox1 and yes it is activex control
and yes if it is A then it looks like
AA
BB
CC
 
Last edited:
Upvote 0
What does this mean:

"would fill with AA,BB,CC"

You want all the values in column A B and C. Or what?
 
Upvote 0
Not quite understanding what the question is, but the following maybe?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target = Sheet1.Range("B1") Then


    If Sheet1.Range("B1").Value2 = "A" Then
    
        With Sheet1.ComboBox1
            .AddItem "This"
            .AddItem "Is"
            .AddItem "A"
            .AddItem "Test"
        End With
        
    End If
    
End If


End Sub
 
Upvote 0
I mean to say that combobox fills with mentioned value
like


Sub Worksheet_Change(ByVal Target As Range)<strike></strike>

If range b1 a text A then combobox1 would fill with AA,BB,CC

If range b1 a text B then combobox1 would fill with DD,EE,FF

If range b1 a text C then combobox1 would fill with GG,HH,LL
 
Upvote 0
Not quite understanding what the question is, but the following maybe?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target = Sheet1.Range("B1") Then


    If Sheet1.Range("B1").Value2 = "A" Then
    
        With Sheet1.ComboBox1
            .AddItem "This"
            .AddItem "Is"
            .AddItem "A"
            .AddItem "Test"
        End With
        
    End If
    
End If


End Sub
[/QUOTE

Red Thanks for your reply but you didn't apply mentioned all three condition and further combobox1 is not clear when required condition does not match
 
Upvote 0
Something like this :
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim sValue As String
    
    If Target.Address = Range("B1").Address Then
        Select Case Target.Value2
            Case "A"
                sValue = "AA,BB,CC"
            Case "B"
                sValue = "DD,EE,FF"
            Case "C"
                sValue = "GG,HH,LL"
            Case Else
                Exit Sub
        End Select
        With ComboBox1
            On Error Resume Next
                .Clear
            On Error GoTo 0
            .AddItem Split(sValue, ",")(0)
            .AddItem Split(sValue, ",")(1)
            .AddItem Split(sValue, ",")(2)
        End With
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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