View Single Post
 
Old 01-31-2017, 08:17 PM
ThisGuyJohn ThisGuyJohn is offline Windows 7 64bit Office 2016
Novice
 
Join Date: Jan 2017
Posts: 6
ThisGuyJohn is on a distinguished road
Smile Deleting rows based on the text in certain cells VBA

Hello all this is my first post

So what I am trying to do is wright a macro to delete certain ROWS based on text in certain cells down COLUMN P for example look down COLUMN P and delete all rows with "Available"
BUT also looking down COLUMN C and M and saving ROWS with certain text in them
so save all ROWS in COLUMN C that have the text with "Agent:..." and "Date:..." and the text in COLUMN M with the specific text of "Break (Aux 2 - Agero Aux 4 - MG Break - Aux 71 HRB)"


so I can get excel to do all of this but look down COLUMN M if I take out all the code that has to do with COLUMN M everything works how I want it to. but when I add the code for COLUMN M I get this error
run time error 1004
application defined or object defined error
and excel highlights this row of code in yellow

Code:
For m = .Cells(Rows.Count, "M").End(x1up).Row To 1 Step -1 'COLUMN M
This is the full code

Code:
Sub Filter()
    Dim c As Long
    Dim m As Long
    With ActiveSheet
        For c = .Cells(Rows.Count, "C").End(xlUp).Row To 1 Step -1 'COLUMN C
        For m = .Cells(Rows.Count, "M").End(x1up).Row To 1 Step -1 'COLUMN M
            With .Rows(c)
            With .Rows(m)
            
                'look at COLUMN P and delete ROWS with specific text
            
                If .Range("P1").Value = "System Issues" Or .Range("P1").Value = "SME Floor Walker" Or .Range("P1").Value = "Coaching" Or .Range("P1").Value = "Not Scheduled" Or .Range("P1").Value = "Not Set Ready" Or .Range("P1").Value = "Available" Or .Range("P1").Value = vbNullString Then
                
                   'saves ROWS with text like "Agent:*" in COLUMN C
            
                    If Not .Range("C1").Value Like "Agent:*" Then
                    
               'look at COLUMN P and delete ROWS with specific text
            
                If .Range("P1").Value = "System Issues" Or .Range("P1").Value = "SME Floor Walker" Or .Range("P1").Value = "Coaching" Or .Range("P1").Value = "Not Scheduled" Or .Range("P1").Value = "Not Set Ready" Or .Range("P1").Value = "Available" Or .Range("P1").Value = vbNullString Then
                
                    'saves ROWS with text like "Date:*" in COLUMN C
            
                    If Not .Range("C1").Value Like "Date:*" Then
                    
                'look at COLUMN P and delete ROWS with specific text
            
                If .Range("P1").Value = "System Issues" Or .Range("P1").Value = "SME Floor Walker" Or .Range("P1").Value = "Coaching" Or .Range("P1").Value = "Not Scheduled" Or .Range("P1").Value = "Not Set Ready" Or .Range("P1").Value = "Available" Or .Range("P1").Value = vbNullString Then
                
                    'saves ROWS with the text "Break (Aux 2 - Agero Aux 4 - MG Break - Aux 71 HRB)" in COLUMN M
            
                    If Not .Range("M1").Value = "Break (Aux 2 - Agero Aux 4 - MG Break - Aux 71 HRB)" Then
                        'deletes ALL ROWS that were not saved
            
                        .Delete
                        
                    End If
                    End If
                    End If
                End If
                End If
                End If
            End With
            End With
        Next m
        Next c
    End With
    
End Sub
Reply With Quote