Macro to delete rows in excel to cell with specific key word in excel and next find if cell in row is blank then delete row with blank cell and above

Kuldip

New Member
Joined
May 23, 2016
Messages
2
Frnds,


I need a Macro to delete rows in excel to cell with specific keyword "Job Number" in excel and next find if cell exactly next row is blank, if yes then delete this row with blank cell and above two.

Report Data copy
Data 1
Job NoDateClientAccountGroup AccountLocationStatus
XXX123417 May 16ABCCDFEFGUSAPending
XXX123518 May 16GDCADFEFGUSAPending
Data 2
Job NoDateClientAccountGroup AccountLocationStatus
Data 3
Job NoDateClientAccountGroup AccountLocationStatus
XXX123417 May 16ABCCDFEFGBRACompleted
XXX123518 May 16GDCADFEFGUSACompleted
XXX123619 May 16ABCCDFEFGEGYCompleted
XXX123720 May 16GDCADFEFGSRTPending
Data 4
Job NoDateClientAccountGroup AccountLocationStatus
Data 5
Job NoDateClientAccountGroup AccountLocationStatus
XXX123619 May 16ABCCDFEFGEGYCompleted

<tbody>
</tbody>

Expected Results - Deleting blank records and respective headers.

Data 1
Job NoDateClientAccountGroup AccountLocationStatus
XXX123417 May 16ABCCDFEFGUSAPending
XXX123518 May 16GDCADFEFGUSAPending
Data 3
Job NoDateClientAccountGroup AccountLocationStatus
XXX123417 May 16ABCCDFEFGBRACompleted
XXX123518 May 16GDCADFEFGUSACompleted
XXX123619 May 16ABCCDFEFGEGYCompleted
XXX123720 May 16GDCADFEFGSRTPending
Data 5
Job NoDateClientAccountGroup AccountLocationStatus
XXX123619 May 16ABCCDFEFGEGYCompleted

<tbody>
</tbody>



NB, If its a blank records then it will only be single blank row below "Job No" as below, which needs to be deleted in results

Data 4
Job NoDateClientAccountGroup AccountLocationStatus

<tbody>
</tbody>
Thanks in advance for your help.

Rgrds
Kuldip
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Sub DeleteUnwantedRows()


Application.ScreenUpdating = False
Dim x
For x = Cells(Rows.Count, ActiveCell.Column).End(xlUp).Row To ActiveCell.Row Step -1
If Cells(x, 1) = "Job No" And Cells(x + 1, 1) = "" Then
Cells(x, 1).EntireRow.Delete 'Delete the entire row
Cells(x - 1, 1).EntireRow.Delete 'Delete the row above it
Cells(x - 2, 1).EntireRow.Delete 'Delete the row 2 rows above it


End If
Next x
Application.ScreenUpdating = True


End Sub

Thanks guys i got it :) though not perfect but results are somewhat i wanted.
 
Upvote 0

Forum statistics

Threads
1,215,514
Messages
6,125,263
Members
449,219
Latest member
daynle

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