Delete Rows in Table if Field is Blank

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
I am getting an error message: Run Time 1004 Delete Method of Range Class Failed

Here:
Sheets("DS_List").Range("E16:E" & LRowDS).Select
Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete

Any help is appreciated.

Code:
Sub LoadDownSelect()

Application.ScreenUpdating = False

'*******************************************************************
'Unfilter the CMCS Tracker
Sheets("CMCS Tracker").Select
ActiveSheet.AutoFilterMode = False
    Rows("36:36").Select
    Selection.AutoFilter

'*******************************************************************

'First Clear Table

'Clear table
                   
'Clear table - remove all rows except the first row
    Application.ScreenUpdating = False
    
    Sheets("DS_List").Select

    ActiveSheet.ListObjects("DownSelectTable").HeaderRowRange.Select
    'Remove the filters if one exists.
    If ActiveSheet.FilterMode Then
        Selection.AutoFilter
    End If

    'Clear all lines but the first one in the table leaving formulas for the next go round.
    With Worksheets("DS_List").ListObjects("DownSelectTable")
        .Range.AutoFilter
        On Error Resume Next
        .DataBodyRange.Offset(1).Resize(.DataBodyRange.Rows.Count - 1, .DataBodyRange.Columns.Count).Rows.Delete

        If .ListColumns.Count > 1 Then
            .DataBodyRange.Rows(1).SpecialCells(xlCellTypeConstants).ClearContents
        Else
            
            With .DataBodyRange.Cells(1)
            If Not .HasFormula Then .ClearContents

            End With
        
        End If

    End With
    
    Range("B16").Select
    


    
'*******************************************************************
'Copy to SownSelect
'*********************************************************************
Sheets("DS_List").Activate
Sheets("DS_List").Range("B16").Select
'

Dim LastRow As Long

LastRow = Sheets("CMCS Tracker").Cells(Rows.Count, "B").End(xlUp).Row


Sheets("CMCS Tracker").Range("P37:P" & LastRow).Copy
    Sheets("DS_List").Range("B16").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False

Sheets("CMCS Tracker").Range("J37:J" & LastRow).Copy
    Sheets("DS_List").Range("C16").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
    
Sheets("CMCS Tracker").Range("C37:C" & LastRow).Copy
    Sheets("DS_List").Range("D16").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        
Sheets("CMCS Tracker").Range("I37:I" & LastRow).Copy
    Sheets("DS_List").Range("E16").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False

'**********************************************************
'Remove Blanks and Dups

'Remove Duplicates
      Range("DownSelectTable[#All]").Select
    ActiveSheet.Range("DownSelectTable[#All]").RemoveDuplicates Columns:=Array(1, _
        2, 3), header:=xlYes
        
'Delete Rows in  table where CostSourceId is blank
Dim rngBlanks As Excel.Range

With Worksheets("DS_List").ListObjects("DownSelectTable")
    On Error Resume Next
    Set rngBlanks = Intersect(.DataBodyRange, .ListColumns("CostSourceId").Range).SpecialCells(xlCellTypeBlanks)
    On Error GoTo 0
    If Not rngBlanks Is Nothing Then
        rngBlanks.Delete
    End If
End With


'Delete Rows in  table where DSRationale is blank

Sheets("DS_List").Select

Dim LRowDS

LRowDS = Sheets("DS_List").Cells(Rows.Count, "B").End(xlUp).Row

Sheets("DS_List").Range("E16:E" & LRowDS).Select
Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete


Sheets("DS_List").Range("B16").Select


End Sub

Thank you
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Ugh, I could just use the same code that deletes blanks in CostSourceID

Dim rngBlanks As Excel.Range

With Worksheets("DS_List").ListObjects("DownSelectTable")
On Error Resume Next
Set rngBlanks = Intersect(.DataBodyRange, .ListColumns("CostSourceId").Range).SpecialCells(xlCellTypeBlanks)
On Error GoTo 0
If Not rngBlanks Is Nothing Then
rngBlanks.Delete
End If
End With

Got it. Thank you for your time
 
Upvote 0
Solution

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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