need macro to delete rows contain specific text

zaidan

New Member
Joined
Sep 18, 2008
Messages
34
dear all,

I need help : i need macro to delete rows that contain specific text at the middle of the data. In my case : i want to delete rows that contain PPAA in the middle of the data, example :

Data :
2011-05-27 00:19Z 301979885 FTI01 AAXX 27004 97460 11459 70000
2011-05-27 00:36Z 301981102 FTI01 AAXX 27004 97460 11459 70000
2011-05-27 00:46Z 301982166 FTI01 PPAA 77001 97460 55385 14007
2011-05-27 00:46Z 301982171 FTI01 PPAA 77001 97460 55385 14007
2011-05-27 02:55Z 301987965 FTI01 AAXX 27034 97460 31458 72604
2011-05-27 00:48Z 301982299 FTI01 PPAA 77001 97460 90/12 00000

Result I want :
2011-05-27 00:19Z 301979885 FTI01 AAXX 27004 97460 11459 70000
2011-05-27 00:36Z 301981102 FTI01 AAXX 27004 97460 11459 70000
2011-05-27 02:55Z 301987965 FTI01 AAXX 27034 97460 31458 72604

Thanks for any help. :)
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Does your data look something like:
Excel Workbook
ABCDEFGHI
15/27/201100:19Z301979885FTI01AAXX27004974601145970000
25/27/201100:36Z301981102FTI01AAXX27004974601145970000
35/27/201100:46Z301982166FTI01PPAA77001974605538514007
45/27/201100:46Z301982171FTI01PPAA77001974605538514007
55/27/201102:55Z301987965FTI01AAXX27034974603145872604
65/27/201100:48Z301982299FTI01PPAA770019746090/120
Sheet2
Excel 2003
...or ???
 
Upvote 0
Try this:

Code:
Sub deletedata()

i = 1
Do Until IsEmpty(Cells(i, 1))
    If InStr(Cells(i, 1), "PPAA") Then
        Cells(i, 1).Delete Shift:=xlUp
        i = i - 1
    End If
    i = i + 1
Loop

End Sub
 
Upvote 0
Okay, if like:
Excel Workbook
A
1Data :
22011-05-27 00:19Z 301979885 FTI01 AAXX 27004 97460 11459 70000
32011-05-27 00:36Z 301981102 FTI01 AAXX 27004 97460 11459 70000
42011-05-27 00:46Z 301982166 FTI01 PPAA 77001 97460 55385 14007
52011-05-27 00:46Z 301982171 FTI01 PPAA 77001 97460 55385 14007
62011-05-27 02:55Z 301987965 FTI01 AAXX 27034 97460 31458 72604
72011-05-27 00:48Z 301982299 FTI01 PPAA 77001 97460 90/12 00000
Sheet3
Excel 2003
Try:
Rich (BB code):
Option Explicit
    
Sub exa()
Dim lLRow As Long
Dim lRow As Long
    
    With Sheet3 '<---CodeName OR sheet/tab name---> ThisWorkbook.Worksheets("Sheet3")
        lLRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        
        For lRow = lLRow To 2 Step -1 '<---Presumes a header row
            If InStr(1, .Cells(lRow, "A").Value, " PPAA ") Then
                .Rows(lRow).Delete
            End If
        Next
    End With
End Sub
Hope that helps,

Mark
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,345
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top