Remove Rows with Blanks for named worksheet

oplintx

New Member
Joined
Mar 1, 2014
Messages
28
I am needing some vba code to delete rows if columns contain blanks (specifically column E) and define the sheet name as "data". I have 20000 records in this table so I need something efficient. Any help would be appreciated.

[TABLE="width: 763"]
<tbody>[TR]
[TD]Supplier
[/TD]
[TD]Terminal
[/TD]
[TD]Product
[/TD]
[TD]Location
[/TD]
[TD]Manager
[/TD]
[TD]Customer
[/TD]
[TD]Price
[/TD]
[TD]Rank
[/TD]
[TD]Eff.Date
[/TD]
[TD]Eff.Time
[/TD]
[/TR]
[TR]
[TD]Supplier2
[/TD]
[TD]Terminal18
[/TD]
[TD]Product5
[/TD]
[TD]Location1
[/TD]
[TD]Manager1
[/TD]
[TD]Customer1
[/TD]
[TD]Price
[/TD]
[TD="align: right"]1
[/TD]
[TD="align: right"]6/6/18
[/TD]
[TD="align: right"]12:00 AM
[/TD]
[/TR]
[TR]
[TD]Supplier2
[/TD]
[TD]Terminal18
[/TD]
[TD]Product5
[/TD]
[TD]Location1
[/TD]
[TD]Manager1
[/TD]
[TD]Customer1
[/TD]
[TD]Price
[/TD]
[TD="align: right"]1
[/TD]
[TD="align: right"]6/6/18
[/TD]
[TD="align: right"]12:00 AM
[/TD]
[/TR]
[TR]
[TD]Supplier3
[/TD]
[TD]Terminal8
[/TD]
[TD]Product5
[/TD]
[TD]Location6
[/TD]
[TD]Manager2
[/TD]
[TD]Customer2
[/TD]
[TD]Price
[/TD]
[TD="align: right"]3
[/TD]
[TD="align: right"]6/5/18
[/TD]
[TD="align: right"]6:00 PM
[/TD]
[/TR]
[TR]
[TD]Supplier3
[/TD]
[TD]Terminal8
[/TD]
[TD]Product5
[/TD]
[TD]Location6
[/TD]
[TD]Manager2
[/TD]
[TD]Customer2
[/TD]
[TD]Price
[/TD]
[TD="align: right"]3
[/TD]
[TD="align: right"]6/5/18
[/TD]
[TD="align: right"]6:00 PM
[/TD]
[/TR]
[TR]
[TD]Supplier3
[/TD]
[TD]Terminal8
[/TD]
[TD]Product5
[/TD]
[TD]Location6
[/TD]
[TD]Manager2
[/TD]
[TD]Customer2
[/TD]
[TD]Price
[/TD]
[TD="align: right"]8
[/TD]
[TD="align: right"]6/5/18
[/TD]
[TD="align: right"]6:00 PM
[/TD]
[/TR]
[TR]
[TD]Supplier3
[/TD]
[TD]Terminal8
[/TD]
[TD]Product5
[/TD]
[TD]Location6
[/TD]
[TD]Manager2
[/TD]
[TD]Customer2
[/TD]
[TD]Price
[/TD]
[TD="align: right"]8
[/TD]
[TD="align: right"]6/5/18
[/TD]
[TD="align: right"]6:00 PM
[/TD]
[/TR]
[TR]
[TD]Supplier4
[/TD]
[TD]Terminal10
[/TD]
[TD]Product5
[/TD]
[TD]Location6
[/TD]
[TD]Manager2
[/TD]
[TD]Customer2
[/TD]
[TD]Price
[/TD]
[TD="align: right"]5
[/TD]
[TD="align: right"]6/5/18
[/TD]
[TD="align: right"]6:00 PM
[/TD]
[/TR]
[TR]
[TD]Supplier4
[/TD]
[TD]Terminal10
[/TD]
[TD]Product5
[/TD]
[TD]Location6
[/TD]
[TD]Manager2
[/TD]
[TD]Customer2
[/TD]
[TD]Price
[/TD]
[TD="align: right"]5
[/TD]
[TD="align: right"]6/5/18
[/TD]
[TD="align: right"]6:00 PM
[/TD]
[/TR]
[TR]
[TD]Supplier5
[/TD]
[TD]Terminal5
[/TD]
[TD]Product5
[/TD]
[TD]Location5
[/TD]
[TD][/TD]
[TD]Customer2
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Supplier5
[/TD]
[TD]Terminal5
[/TD]
[TD]Product5
[/TD]
[TD]Location5
[/TD]
[TD][/TD]
[TD]Customer2
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Supplier5
[/TD]
[TD]Terminal6
[/TD]
[TD]Product1
[/TD]
[TD]Location5
[/TD]
[TD][/TD]
[TD]Customer2
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Supplier5
[/TD]
[TD]Terminal6
[/TD]
[TD]Product5
[/TD]
[TD]Location5
[/TD]
[TD]Manager2
[/TD]
[TD]Customer2
[/TD]
[TD]Price
[/TD]
[TD="align: right"]2
[/TD]
[TD="align: right"]6/6/18
[/TD]
[TD="align: right"]12:01 AM
[/TD]
[/TR]
[TR]
[TD]Supplier5
[/TD]
[TD]Terminal6
[/TD]
[TD]Product5
[/TD]
[TD]Location5
[/TD]
[TD]Manager2
[/TD]
[TD]Customer2
[/TD]
[TD]Price
[/TD]
[TD="align: right"]2
[/TD]
[TD="align: right"]6/6/18
[/TD]
[TD="align: right"]12:01 AM
[/TD]
[/TR]
[TR]
[TD]Supplier5
[/TD]
[TD]Terminal7
[/TD]
[TD]Product5
[/TD]
[TD]Location11
[/TD]
[TD]Manager2
[/TD]
[TD]Customer2
[/TD]
[TD]Price
[/TD]
[TD="align: right"]3
[/TD]
[TD="align: right"]6/5/18
[/TD]
[TD="align: right"]6:00 PM
[/TD]
[/TR]
[TR]
[TD]Supplier5
[/TD]
[TD]Terminal7
[/TD]
[TD]Product5
[/TD]
[TD]Location11
[/TD]
[TD]Manager2
[/TD]
[TD]Customer2
[/TD]
[TD]Price
[/TD]
[TD="align: right"]2
[/TD]
[TD="align: right"]6/5/18
[/TD]
[TD="align: right"]6:00 PM
[/TD]
[/TR]
[TR]
[TD]Supplier5
[/TD]
[TD]Terminal12
[/TD]
[TD]Product1
[/TD]
[TD]Location10
[/TD]
[TD][/TD]
[TD]Customer2
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Supplier5
[/TD]
[TD]Terminal12
[/TD]
[TD]Product5
[/TD]
[TD]Location10
[/TD]
[TD][/TD]
[TD]Customer2
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Supplier5
[/TD]
[TD]Terminal12
[/TD]
[TD]Product5
[/TD]
[TD]Location10
[/TD]
[TD][/TD]
[TD]Customer2
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Supplier5
[/TD]
[TD]Terminal14
[/TD]
[TD]Product5
[/TD]
[TD]Location11
[/TD]
[TD]Manager3
[/TD]
[TD]Customer2
[/TD]
[TD]Price
[/TD]
[TD="align: right"]1
[/TD]
[TD="align: right"]6/6/18
[/TD]
[TD="align: right"]12:01 AM
[/TD]
[/TR]
[TR]
[TD]Supplier5
[/TD]
[TD]Terminal14
[/TD]
[TD]Product5
[/TD]
[TD]Location11
[/TD]
[TD]Manager3
[/TD]
[TD]Customer2
[/TD]
[TD]Price
[/TD]
[TD="align: right"]1
[/TD]
[TD="align: right"]6/6/18
[/TD]
[TD="align: right"]12:01 AM
[/TD]
[/TR]
[TR]
[TD]Supplier6
[/TD]
[TD]Terminal7
[/TD]
[TD]Product1
[/TD]
[TD]Location11
[/TD]
[TD][/TD]
[TD]Customer2
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Supplier6
[/TD]
[TD]Terminal7
[/TD]
[TD]Product5
[/TD]
[TD]Location11
[/TD]
[TD]Manager3
[/TD]
[TD]Customer2
[/TD]
[TD]Price
[/TD]
[TD="align: right"]3
[/TD]
[TD="align: right"]6/6/18
[/TD]
[TD="align: right"]12:01 AM
[/TD]
[/TR]
[TR]
[TD]Supplier6
[/TD]
[TD]Terminal7
[/TD]
[TD]Product5
[/TD]
[TD]Location11
[/TD]
[TD]Manager3
[/TD]
[TD]Customer2
[/TD]
[TD]Price
[/TD]
[TD="align: right"]2
[/TD]
[TD="align: right"]6/6/18
[/TD]
[TD="align: right"]12:01 AM
[/TD]
[/TR]
[TR]
[TD]Supplier7
[/TD]
[TD]Terminal16
[/TD]
[TD]Location13
[/TD]
[TD]Location15
[/TD]
[TD]Manager3
[/TD]
[TD]Customer2
[/TD]
[TD]Price
[/TD]
[TD="align: right"]1
[/TD]
[TD="align: right"]6/5/18
[/TD]
[TD="align: right"]6:00 PM
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
How about
Code:
Sub DelRows()
   Dim ary As Variant
   Dim Nary As Variant
   Dim r As Long, c As Long, j As Long
   ary = Range("A1").CurrentRegion
   ReDim Nary(1 To UBound(ary), 1 To UBound(ary, 2))
   For r = 1 To UBound(ary)
      If Not IsEmpty(ary(r, 5)) Then
         j = j + 1
         For c = 1 To UBound(ary, 2)
            Nary(j, c) = ary(r, c)
         Next c
      End If
   Next r
   Range("A1").CurrentRegion.Clear
   Range("A1").Resize(j, UBound(Nary, 2)).Value = Nary
End Sub
 
Upvote 0
If you can really get away with just looking at column E, then this one line of VBA code should do that:
Code:
    Columns("E:E").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
 
Last edited:
Upvote 0
How about
Code:
Sub DelRows()
   Dim ary As Variant
   Dim Nary As Variant
   Dim r As Long, c As Long, j As Long
   ary = Range("A1").CurrentRegion
   ReDim Nary(1 To UBound(ary), 1 To UBound(ary, 2))
   For r = 1 To UBound(ary)
      If Not IsEmpty(ary(r, 5)) Then
         j = j + 1
         For c = 1 To UBound(ary, 2)
            Nary(j, c) = ary(r, c)
         Next c
      End If
   Next r
   Range("A1").CurrentRegion.Clear
   Range("A1").Resize(j, UBound(Nary, 2)).Value = Nary
End Sub

How do I name the sheet as "Data". I am running this macro from a button on a different sheet.
 
Upvote 0
Is the sheet already called Data?
If not what is it's current name?
 
Upvote 0
Sheet name is already named data.

I just tested the previous code. The eff.time is being reformatted from 6:00 PM to .75.

Thanks for the quick response.
[TABLE="width: 84"]
<tbody>[TR]
[TD="align: right"][/TD]
[/TR]
</tbody><colgroup><col></colgroup>[/TABLE]
 
Upvote 0
OK, how about
Code:
Sub DelRows()
   Dim ary As Variant
   Dim Nary As Variant
   Dim r As Long, c As Long, j As Long
   ary = Sheets("Data").Range("A1").CurrentRegion
   ReDim Nary(1 To UBound(ary), 1 To UBound(ary, 2))
   For r = 1 To UBound(ary)
      If Not IsEmpty(ary(r, 5)) Then
         j = j + 1
         For c = 1 To UBound(ary, 2)
            Nary(j, c) = ary(r, c)
         Next c
      End If
   Next r
   With Sheets("Data")
      .Range("A1").CurrentRegion.Clear
      .Range("A1").Resize(j, UBound(Nary, 2)).Value = Nary
      .Range("J:J").NumberFormat = "h:mm AM/PM"
   End With
End Sub
 
Upvote 0
OK, how about
Code:
Sub DelRows()
   Dim ary As Variant
   Dim Nary As Variant
   Dim r As Long, c As Long, j As Long
   ary = Sheets("Data").Range("A1").CurrentRegion
   ReDim Nary(1 To UBound(ary), 1 To UBound(ary, 2))
   For r = 1 To UBound(ary)
      If Not IsEmpty(ary(r, 5)) Then
         j = j + 1
         For c = 1 To UBound(ary, 2)
            Nary(j, c) = ary(r, c)
         Next c
      End If
   Next r
   With Sheets("Data")
      .Range("A1").CurrentRegion.Clear
      .Range("A1").Resize(j, UBound(Nary, 2)).Value = Nary
      .Range("J:J").NumberFormat = "h:mm AM/PM"
   End With
End Sub

That worked like a champ!!! thank you so much. I am still learning vb and you are very helpful.
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

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