VBA to delete rows based on empty cell

Johnson Boni

New Member
Joined
Feb 9, 2020
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hi.

Brand new here and to the world of VBA and MACROS.

I need help with a certain situation I have.

I have a workbook with twelve worksheets, sheet 1 - sheet 12. A lot of data but what I need to concentrate on is column d. I would like assistance with a vba code that would delete the entire row if the cell in column d is empty. There are three groupings. I really have no control over this as the template is controlled and not much I can do to change it.

Lets say the ranges are D3:D28, D35:D40, and D50:D55. Should any of the cells be empty the entire row to be deleted and to repeat for all twelve sheets.

Thank you!
 
VBA Code:
Sub DeleteRows()
Dim ws As Worksheet
On Error Resume Next
For Each ws In Worksheets
    ws.[D:D].SpecialCells(xlCellTypeFormulas, 16).EntireRow.Delete
Next
End Sub
OR :
VBA Code:
Sub DeleteRows()
Dim x%
On Error Resume Next
For x = 1 To 12
    Sheets("Sheet" & x).[D:D].SpecialCells(xlCellTypeFormulas, 16).EntireRow.Delete
Next
End Sub
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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