Announcement

Collapse
No announcement yet.

Macro to delete rows if they do not contain specific text

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Macro to delete rows if they do not contain specific text



    Hello,

    I am currently working on a macro that will scan columns "E" and "I" and if they do not contain "Inserted" or "ClassID" the row should be deleted. I've tried multiple different variations but can't seem to get it right.. below is what I have so far:

    Sub EvaluateD()
    Dim i, LastRow
    Dim UserIDModLog

    UserIDModLog = ActiveSheet.Name

    LastRow = UserIDModLog(Rows.Count).End(xlUp).Row
    For i = LastRow To 1 Step -1
    If UserIDModLog.Value <> "Inserted" Or "ClassID" Then
    Else
    UserIDModLog.EntireRow.Delete
    End If
    Next i
    End Sub


    Help

  • #2


    .
    This is one method :

    Code:
    Option Explicit
    
    Sub Maybe2()
        Dim lr As Long
        Application.ScreenUpdating = False    '\/Change number 1 below to correspond to affected column.
        lr = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row '<----- Change to actual sheet name
        
        With Range("A1:A" & lr)                                   '<-- Change to corresponding row
            .Replace "Inserted", "", xlWhole                               '<-- Currently checking for number Inserted. Edit as required
            .SpecialCells(4).EntireRow.Delete
        End With
        
        lr = Sheets("Sheet1").Cells(Rows.Count, 9).End(xlUp).Row  '\/Change number 9 to correspond to affected column.
        With Range("I1:I" & lr)                                   '<-- Change to corresponding row
            .Replace "ClassID", "", xlWhole                               '<-- Currently checking for number ClassID. Edit as required
            .SpecialCells(4).EntireRow.Delete
        End With
        
        Application.ScreenUpdating = True
    End Sub

    Comment

    Working...
    X