Delete Rows in a table if blank

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
I have this code that seems to work for everything except deleting rows if DSRationale is blank

I checked the table field name and it is "DSRationale"

I know the tab name and table name is correct because the code does delete rows if "CostSourceId" is blank.

Does anyone see where I made the mistake? Its not deleting rows where the DSRationale is blank. Thanks!!

Code:
Sub TestThis()

'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("DownSelctions").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
Dim rngBlankDS As Excel.Range

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

End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I figured out the problem, but not a solution.

The rows in the column appear to be blank but I am guessing they are not actually blank. If I click into one of them and hit delete, and then run the code - that row does get deleted.

So now my question is how do I delete these rows if null? I guess!!
 
Upvote 0

this link will help to identify that you have non printing characters. You may want to include a step in your macro to clean your range of data and see if that solves your issue.
 
Upvote 0
Solution
I am now clearing that row of data in the very begining steps.

This seems to be working

Code:
Sub ClearcellsX ()
Dim CMCSLR As Long

    CMCSLR = Sheets("CMCS Tracker").Cells(Rows.Count, "C").End(xlUp).Row

    Sheets("CMCS Tracker").Range("I37:I" & CMCSLR).Select
        Selection.ClearContents
End Sub
 
Upvote 0
I am now clearing that row of data in the very begining steps.

This seems to be working

Code:
Sub ClearcellsX ()
Dim CMCSLR As Long

    CMCSLR = Sheets("CMCS Tracker").Cells(Rows.Count, "C").End(xlUp).Row

    Sheets("CMCS Tracker").Range("I37:I" & CMCSLR).Select
        Selection.ClearContents
End Sub
Drop the select part:
VBA Code:
Sub ClearcellsX()
Dim CMCSLR As Long

    CMCSLR = Sheets("CMCS Tracker").Cells(Rows.Count, "C").End(xlUp).Row

    Sheets("CMCS Tracker").Range("I37:I" & CMCSLR).ClearContents
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,848
Messages
6,121,917
Members
449,055
Latest member
KB13

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