Public Property Get CrWS() As Worksheet
Set CrWS = Sheets("ورقة1")
End Property
Private Sub UserForm_Initialize()
Dim Tbl As Object, c As Range, temp As Variant, lastRow As Long
Set Tbl = CreateObject("Scripting.Dictionary")
lastRow = CrWS.Cells(CrWS.Rows.Count, "B").End(xlUp).Row
If lastRow > 1 Then
For Each c In CrWS.Range("B2:B" & lastRow)
If c.Value <> "" Then Tbl.Item(c.Value) = c.Value
Next c
End If
If Tbl.Count > 0 Then
temp = Tbl.items
Me.ComboBox1.List = temp
End If
End Sub
Private Sub CommandButton1_Click()
Dim lastRow As Long, ky As String
If Me.ComboBox1.Value <> "" Then
ky = "=*" & Me.ComboBox1.Value & "*"
lastRow = CrWS.Cells(CrWS.Rows.Count, "B").End(xlUp).Row
If lastRow < 2 Then Exit Sub
Application.ScreenUpdating = False
With CrWS.Range("B1:B" & lastRow)
.AutoFilter Field:=1, Criteria1:=ky
End With
On Error Resume Next
CrWS.Range("A2:C" & lastRow).SpecialCells(xlCellTypeVisible).EntireRow.Delete
On Error GoTo 0
CrWS.AutoFilterMode = False
Application.ScreenUpdating = True
Unload Me
End If
End Sub
السلام عليكم ممكن تعديل على الكود ليعمل على ملف اخر مفتوح وليكن اسمه كلية واسم الشيت القسم مع جزيل الشكر
كلية.xlsb
ملف الاصلي.xlsb