اذهب الي المحتوي
أوفيسنا

الردود الموصى بها

  • أفضل إجابة
قام بنشر

First correct the combobox name from [Calss] to [Class]

In userform module

Dim ws As Worksheet, m As Long
Private Sub StudentName_Enter()
    Dim a, i As Long, k As Long
    If Natija.Value <> "" And Class <> "" Then
        a = ws.Range("A2:D" & m).Value
        ReDim b(1 To UBound(a, 1))
        For i = LBound(a) To UBound(a)
            If Val(a(i, 3)) = Val(Class.Value) And a(i, 4) = Natija.Value Then
                k = k + 1
                b(k) = a(i, 2)
            End If
        Next i
        If k > 0 Then ReDim Preserve b(1 To k): StudentName.List = b
    End If
End Sub
Private Sub UserForm_Initialize()
    Dim a
    Set ws = Worksheets("Sheet1")
    m = ws.Cells(Rows.Count, "B").End(xlUp).Row
    a = GetDistinct(ws.Range("D2:D" & m))
    Natija.List = a
    a = GetDistinct(ws.Range("C2:C" & m))
    Class.List = a
End Sub
Function GetDistinct(ByVal oTarget As Range) As Variant
    Dim vArr, v, dic As Object
    Set dic = CreateObject("Scripting.Dictionary")
    vArr = oTarget
    For Each v In vArr
        If Not IsEmpty(v) Then dic(v) = v
    Next v
    GetDistinct = dic.Items()
End Function

 

  • Like 4

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • تصفح هذا الموضوع مؤخراً   0 اعضاء متواجدين الان

    • لايوجد اعضاء مسجلون يتصفحون هذه الصفحه
×
×
  • اضف...

Important Information