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

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.

Forum statistics

Threads
1,214,411
Messages
6,119,360
Members
448,888
Latest member
Arle8907

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