VBA - Delete all rows except rows which contain certain text

Giggs1991

Board Regular
Joined
Mar 17, 2019
Messages
50
Hi All,

I have a excel workbook with 2 worksheets.
Worksheet A has a very badly formatted data dump from our timesheet tool.
Worksheet B has a list of project names.

I am looking for a vba code which when run will delete all rows in Worksheet A expect for rows which have dates in them and rows which have project names from Worksheet B.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
giggs, try this:

first, on worksheet A, add 3 columns to establish the criteria for deletion so it looks like this:

worksheet_A_formula_results.jpg


.....which is established by writing these formulas in the last 3 columns:

worksheet_A_formulas.jpg


and assuming your worksheet B looks like this:

worksheet_B_project_names.jpg


....then all you would need to do is run this code behind worksheet A:
Code:
Function del_rows_without_date_and_project()
Dim r As Range
Application.ScreenUpdating = False
    For Each r In Range("h2", Range("h2").End(xlDown))
        If r = "YES" Then 'DELETE THE ROW, OUR FORMULAS TELL US THE CRITERIA IS SET FOR THIS ROW
            r.EntireRow.Delete (xlUp)
        End If
    Next r
Application.ScreenUpdating = True
End Function
 
Upvote 0

Forum statistics

Threads
1,224,739
Messages
6,180,674
Members
452,993
Latest member
FDARYABEE

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