VBA Excel- populate combobox2 dependent on Combobox1

Raymondc190466

New Member
Joined
Aug 19, 2016
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Dear All,

I want ComboBox2 to be populated depending on the value choosen in ComboBox1.

1641564650184.png


I have created 3 name ranges:
Vendor = Column A => =OFFSET(Supplier!$A$2;1;0;COUNTA(Supplier!$A:$A)-1)
VendorNumber = Column B => =OFFSET(Supplier!$B$2;1;0;COUNTA(Supplier!$B:$B)-1)
Material = Column C => =OFFSET(Supplier!$C$2;1;0;COUNTA(Supplier!$C:$C)-1)

Present code to populate ComboBox1:

Rich (BB code):
Private Sub UserForm_Initialize()
Set xRg = Worksheets("Supplier").Range("A2:C127")
    Me.ComboBox1.List = xRg.Columns(1).Value

I have below code to populate the textbox7:

VBA Code:
Private Sub ComboBox1_Change()

    'Select Supplier - ComboBox1, autofill Textbox7 with Suppliernumber

Dim xRg As Range
 
    With Worksheets("Supplier")
        Set xRg = .Range("A2:C" & .Range("A" & .Rows.Count).End(xlUp).Row)
    End With
 
    If IsError(Application.VLOOKUP(Me.ComboBox1.Value, xRg, 2, False)) Then
        MsgBox "Start new Complaint " & Me.ComboBox1.Value
    Else
        Me.TextBox7.Text = Application.VLOOKUP(Me.ComboBox1.Value, xRg, 2, False)
    End If

End Sub

What code do I need to get this in the ComboBox1_Change and to fill Combobox2?
 
Last edited:

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Dear All,

I have found a solution (google is my friend):

VBA Code:
Private Sub cboSupplier_Change()

    'Select Supplier, autofill Textbox with Suppliernumber

Dim xRg As Range
Dim r As Integer
Dim ws As Worksheet

Worksheets("Supplier").Activate
    
r = 2

Range("F2").Value = cboSupplier.Value

Columns("C:D").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _
        "F1:F2"), CopyToRange:=Range("H1:I1"), Unique:=False

cboMaterial.Clear

Do Until Cells(r, 9).Value = ""
    cboMaterial.AddItem Cells(r, 9).Value
    r = r + 1
Loop

With Worksheets("Supplier")
        Set xRg = .Range("A2:B127" & .Range("A" & .Rows.Count).End(xlUp).Row)
    End With
  
    If IsError(Application.VLookup(Me.cboSupplier.Value, xRg, 2, False)) Then
        MsgBox "Start new Complaint " & Me.cboSupplier.Value
    Else
        Me.txtSupNr.Text = Application.VLookup(Me.cboSupplier.Value, xRg, 2, False)
    End If

End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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