Function to if empty cells present in a column. If yes, delete the corresponding row.

Shardey

New Member
Joined
Aug 24, 2022
Messages
28
Office Version
  1. 365
  2. 2021
  3. 2016
Platform
  1. Windows
Sub DelRow()

Sheets("ABCD").Select
Columns("W:W").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete

Sheets("XYZA").Select
Columns("W:W").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.EntireRow.Delete

End Sub

This code helps me to select and delete the corresponding row to every blank cell in the column W for two different sheets. This works great if the column actually has empty cell. (Used a macro recorder for it). I need a test to first check if blank cells are present, only then do this.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi Shardey,

Try this:

VBA Code:
Option Explicit
Sub DelBlankRows()

    Dim ws As Worksheet
    Dim varSheet As Variant
    Dim lngLastRow As Long
    
    Application.ScreenUpdating = False
    
    For Each varSheet In Array("ABCD", "XYZA")
        Set ws = ThisWorkbook.Sheets(CStr(varSheet))
        lngLastRow = ws.Cells(Rows.Count, "W").End(xlUp).Row
        If Application.WorksheetFunction.CountIf(ws.Range("W1:W" & lngLastRow), "") > 0 Then
            ws.Range("W1:W" & lngLastRow).SpecialCells(xlCellTypeBlanks).Delete
        End If
        Set ws = Nothing
    Next varSheet
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0
Solution

Forum statistics

Threads
1,214,864
Messages
6,121,986
Members
449,060
Latest member
mtsheetz

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