Delete a row if a specific word(s) are in cell a or b

Wayne Rogers

New Member
Joined
Aug 5, 2014
Messages
17
Good Afternoon folks,

I have a workbook that runs several macros from data imported from my work system, all of which works fine.

Apart from one report whereby I need to delete a varying number of lines from an individual workbook. The workbook in particular imports the data and sorts and arranges the report in a certain way that we use for work purposes. But I now it to deletes the unusable data at the bottom of the report. Unfortunately the bottom of the report varies with each report.

I need to delete rows where a certain cell in a or b contains words such as Print Date : or Print By : or Store Refund Report

I hope I've explained it clearly enough

Many thanks

Wayne
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hello Wayne,

I found this from Ron DeBruin which may be useful.

I must not have copied the whole code on my first post. Here also is a link: Delete row if a specific value exist (VBA)

Code:
Sub Loop_Example()
    Dim Firstrow As Long
    Dim Lastrow As Long
    Dim Lrow As Long
    Dim CalcMode As Long
    Dim ViewMode As Long


    With Application
        CalcMode = .Calculation
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
    End With


    'We use the ActiveSheet but you can replace this with
    'Sheets("MySheet")if you want
    With ActiveSheet


        'We select the sheet so we can change the window view
        .Select


        'If you are in Page Break Preview Or Page Layout view go
        'back to normal view, we do this for speed
        ViewMode = ActiveWindow.View
        ActiveWindow.View = xlNormalView


        'Turn off Page Breaks, we do this for speed
        .DisplayPageBreaks = False


        'Set the first and last row to loop through
        Firstrow = .UsedRange.Cells(1).Row
        Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row


        'We loop from Lastrow to Firstrow (bottom to top)
        For Lrow = Lastrow To Firstrow Step -1


            'We check the values in the A column in this example
            With .Cells(Lrow, "A")


                If Not IsError(.Value) Then


                    If .Value = "ron" Then .EntireRow.Delete
                    'This will delete each row with the Value "ron"
                    'in Column A, case sensitive.


                End If


            End With
            With .Cells(Lrow, "B")


                If Not IsError(.Value) Then


                    If .Value = "ron" Then .EntireRow.Delete
                    'This will delete each row with the Value "ron"
                    'in Column B, case sensitive.


                End If


            End With
        Next Lrow


    End With


    ActiveWindow.View = ViewMode
    With Application
        .ScreenUpdating = True
        .Calculation = CalcMode
    End With


End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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