اذهب الي المحتوي
أوفيسنا
بحث مخصص من جوجل فى أوفيسنا
Custom Search

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

قام بنشر
Sub Test()
    Dim Cel As Range
    For Each Cel In Sheet2.Range("B1:B" & Sheet1.Cells(Rows.Count, "B").End(xlUp).Row)
        If Cel.Value = "كلية التربية" Then Cel.EntireRow.Delete
    Next Cel
End Sub

السلام عليكم المطلوب التعديل على الكود لحذف الصفوف التي تحتوي على كلية التربية ومعهد عالي في العمود B مع العلم عدد الصفوف كثيره في الملف

مسح صفوف معينة بناء على قيمتها.xlsx

قام بنشر

وعليكم السلام ورحمة الله تعالى وبركاته 

Sub test()
    Dim CrWS As Worksheet
    Dim lastRow As Long, tmps As Variant
    
    tmps = Array("=*كلية التربية*", "=*معهد عالي*")
    
    Set CrWS = Sheets("ورقة1")
    
    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:=tmps, Operator:=xlFilterValues
    End With
    On Error Resume Next
    CrWS.Range("A2:C" & lastRow).SpecialCells(xlCellTypeVisible).Delete Shift:=xlUp
    On Error GoTo 0
    
    CrWS.AutoFilterMode = False
    
    Application.ScreenUpdating = True
End Sub

 

  • Like 1
قام بنشر (معدل)

إدا كنت ترغب في إستخدام الإقتراح المقدم من الأستاد  @أبوعيد

يمكنك تجربة هدا 

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

 

 

مسح صفوف معينة بناء على قيمتها v2.xlsb

تم تعديل بواسطه محمد هشام.
  • Like 1

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