Using Class Module of ComboBox to Change Other Combobox

Peinecone

New Member
Joined
Oct 20, 2007
Messages
47
These classes are killing me. I have set up a few classes , but am struggling with this one. This is the code I have for the comboboxes right now. I have this code duplicated for each of 20 boxes.
Code:
Private Sub cboIng1_Change()
   Dim varMatch
   cboUnit1.Clear
   ' check the combo is not blank
   If cboIng1.Value <> "" Then
      varMatch = Application.Match(cboIng1.Value, Range("Ing").Columns(1), 0)
      ' check for no matching data
      If Not IsError(varMatch) Then
         With cboUnit1
            .AddItem Range("Ing").Cells(varMatch, 6)
            .AddItem Range("Ing").Cells(varMatch, 8)
            .AddItem Range("Ing").Cells(varMatch, 10)
         End With
      End If
    End If
End Sub
Essentially what I want to do is have a class module for a cboIng() and when the value for it changes, it will update the list of cboUnit(). I set up the class module clsIng, but can't get it to change cboUnit.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
This is what I have come up with so far. This is in the UserForm Initialize
Code:
    With Me
        For i = 1 To 20
        Set cboIng(i).Ing = .Controls("cboIng" & i)
        Set cboUni(i).Ing = .Controls("cboUni" & i)
        Next i
    End With
And this is in the userform code
Code:
Dim cboIng(20), cboUni(20) As New clsIng

Option Explicit
And this is what I have for the class code clsIng
Code:
Option Explicit

Public WithEvents Ing As MSForms.ComboBox


Private Sub Ing_Change()
Dim varMatch
Dim i
Dim cIng, cUnit

   i = Mid(Ing.Name, 7, 99)
   On Error Resume Next
   With Ing.Parent
   cIng = .Controls("cboIng" & i)
   cUnit = .Controls("cboUni" & i)
   cUnit.Clear
   ' check the combo is not blank
   If cIng <> "" Then
      varMatch = Application.Match(cIng.Value, Range("Ing").Columns(1), 0)
      ' check for no matching data
      If Not IsError(varMatch) Then
         With cUnit
            .AddItem Range("Ing").Cells(varMatch, 6)
            .AddItem Range("Ing").Cells(varMatch, 8)
            .AddItem Range("Ing").Cells(varMatch, 10)
         End With
      End If
    End If
    End With
End Sub
I changed the second combobox name from cboUnit() to cboUni() so the string length is the same as cboIng(). But now the values in cboUni are only changing when I select that combobox, instead of changing when I select the cboIng. I think I am close (or could be totally wrong.) I don't know how to have it only change when cboIng changes, and still include cboUni in the class module.
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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