Delete line in a Table when the the cell is empty

Romano_odK

Active Member
Joined
Jun 4, 2020
Messages
379
Office Version
  1. 365
Platform
  1. Windows
Good morning,

Is it possible to delete a whole line with VBA when in my case in column W the values in the cells starting from line 7 until the end are empty with the push of a button?

Thank you for your time?

Romano
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
How to identify which row in column W is the last row?
We need a screenshot/image of worksheet to see a larger picture.
 
Upvote 0
Hi...

So are you wanting to delete the entire row if the rows starting from row 7 in Column W are empty?
 
Upvote 0
Hi...

So are you wanting to delete the entire row if the rows starting from row 7 in Column W are empty?
The table rows start at row 7 and down to the end, so I need every row to be deleted when the cell on the same row in the column W is empty. Can you do this?
 
Upvote 0
This will delete entirerow till row 10000
Code:
 range("W7:W10000").specialcells(xlcelltypeblanks).entirerow.delete
 
Upvote 0
This will delete entirerow till row 10000
Code:
 range("W7:W10000").specialcells(xlcelltypeblanks).entirerow.delete
Thank you for your help. Unfortunately it doesn't seem to work in my table. "Delete method of Range class failed". What can be the cause of this?
 
Upvote 0
Is your data inside a Named Table e.g. Table1 or is it a normal range?
 
Upvote 0
Try the below... ( @bebo021999 ) can confirm also if correct....

VBA Code:
Sub Del_Blank()
  Dim Rng As Range
  On Error Resume Next
  Set Rng = Range("Table_Query_from_A100[[[COLOR=rgb(226, 80, 65)]Column15[/COLOR]]]").SpecialCells(xlCellTypeBlanks) 'Change the text in red to your column header name...e.g. Column15 to whatever your header name is
  On Error GoTo 0
  If Not Rng Is Nothing Then
    Rng.Delete Shift:=xlUp
  End If
End Sub
 
Upvote 0
Try the below... ( @bebo021999 ) can confirm also if correct....

VBA Code:
Sub Del_Blank()
  Dim Rng As Range
  On Error Resume Next
  Set Rng = Range("Table_Query_from_A100[[[COLOR=rgb(226, 80, 65)]Column15[/COLOR]]]").SpecialCells(xlCellTypeBlanks) 'Change the text in red to your column header name...e.g. Column15 to whatever your header name is
  On Error GoTo 0
  If Not Rng Is Nothing Then
    Rng.Delete Shift:=xlUp
  End If
End Sub

So your code would be like below...

VBA Code:
Sub Del_Blank()
  Dim Rng As Range
  On Error Resume Next
  Set Rng = Range("Table1[[YourHeaderNameForColumnW]]").SpecialCells(xlCellTypeBlanks) ' Replace YourHeaderNameForColumnW with your header name
  On Error GoTo 0
  If Not Rng Is Nothing Then
    Rng.Delete Shift:=xlUp
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,418
Messages
6,124,793
Members
449,189
Latest member
kristinh

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