Help with applying code
Hi,
Have made a couple of adjustments and also note the comments. The following
now appears to test OK. Have not tested all of the code that you posted, only
the part to populate the second combo box based on the selection in the first
combo.
Also everyone appreciates an acknowledgement to an answer (Whether it works
or not). I see that you have used code from a previous answer that I provided
but you didn't previously acknowledge whether it answered your question
satisfactorily.
Private Sub UserForm_Initialize()
CbxMfg.RowSource = _
Worksheets("MANCODE").Range("A2:A1000").Address(ex ternal:=True)
'CboFire.RowSource = _
Worksheets("Lists").Range("D2:D5").Address(externa l:=True)
'CboHealth.RowSource = _
Worksheets("Lists").Range("D2:D5").Address(externa l:=True)
'CboReact.RowSource = _
Worksheets("Lists").Range("D2:D5").Address(externa l:=True)
'CboDisp.RowSource = _
Worksheets("Lists").Range("E2:E4").Address(externa l:=True)
'CboDept.RowSource = _
Worksheets("Lists").Range("C2:C10").Address(extern al:=True)
End Sub
Private Sub CbxMfg_Change()
Dim S As String
Dim V As Variant
Dim J As Range
S = Me.CbxMfg.Text
'V = Application.Match(S, Worksheets("MANCODE") _
.Range("A2:A1000"), 0)
'Note: V in above line will never be an error
'because it is a numeric value representing
'the position in range A2:A1000 of the selection
'and the selection is the Rowsource of the combo so
'it must be found in that range.
'Is it supposed to test in Procode not MANCODE as follows?
V = Application.Match(S, Worksheets("ProCode") _
.Range("A2:A1000"), 0)
'Use If/Else/End If test as follows:-
If IsError(V) = True Then
'Next section commented out by OssieMac
'for testing purposes. Don't know if it works
'FrmProduct.Hide
'FrmManu.Show
Else
With Me.CbxProd
'Following required if you go back
'and change selection in CbxMfg.
'If DbxProd is empty then it is ignored.
If .ListCount 0 Then
For i = .ListCount - 1 To 0 Step -1
.RemoveItem (i)
Next i
End If
For Each J In Worksheets("ProCode").Range("A2:A1000")
If J.Text = S Then
.AddItem J(1, 2)
End If
Next J
.SetFocus
If .ListCount 0 Then
.ListIndex = 0
End If
End With
End If
End Sub
Regards,
OssieMac
|