ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting Blank Cells then deleting those rows (https://www.excelbanter.com/excel-programming/437565-selecting-blank-cells-then-deleting-those-rows.html)

Mikey

Selecting Blank Cells then deleting those rows
 
Ryan responded with this code to highlight the cells. What code would delete
the rows?
------------------------
So you just want to "Select" the cell? Use this,

Sub Highlighter()

Dim lngLastRow As Long
Dim rng As Range

lngLastRow = Cells(Rows.Count, "D").End(xlUp).Row

For Each rng In Range("D1:D" & lngLastRow)
If IsEmpty(rng) Then
rng.Select
Exit For
End If
Next rng

End Sub
--
Cheers,
Ryan


--
Mickey

Mike H

Selecting Blank Cells then deleting those rows
 
Try this

Sub Highlighter()
Dim lngLastRow As Long
Dim rng As Long
LastRow = Cells(Rows.Count, "D").End(xlUp).Row
For rng = LastRow To 1 Step -1
If IsEmpty(Cells(rng, 4)) Then
Cells(rng, 4).EntireRow.Delete
End If
Next rng
End Sub

Mike

"Mikey" wrote:

Ryan responded with this code to highlight the cells. What code would delete
the rows?
------------------------
So you just want to "Select" the cell? Use this,

Sub Highlighter()

Dim lngLastRow As Long
Dim rng As Range

lngLastRow = Cells(Rows.Count, "D").End(xlUp).Row

For Each rng In Range("D1:D" & lngLastRow)
If IsEmpty(rng) Then
rng.Select
Exit For
End If
Next rng

End Sub
--
Cheers,
Ryan


--
Mickey


Ryan H

Selecting Blank Cells then deleting those rows
 
You would have to modify the code to a For...Next Loop instead of a For Each
Loop. I wrote two different ways to delete empty rows. You can decide which
you prefer.

OPTIOIN 1:

Sub DeleteRows1()

Dim lngFirstRow As Long
Dim lngLastRow As Long
Dim i As Long

lngFirstRow = 1
lngLastRow = Cells(Rows.Count, "D").End(xlUp).Row

For i = lngLastRow To lngFirstRow Step -1
If Cells(i, "D") = "" Then
Rows(i).Delete SHift:=xlUp
End If
Next i

End Sub


OPTION 2:

Sub DeleteRows2()

Dim lngFirstRow As Long
Dim lngLastRow As Long

lngFirstRow = 1
lngLastRow = Cells(Rows.Count, "D").End(xlUp).Row

With Sheets("Sheet1")
.Range(.Cells(lngFirstRow, "D"), .Cells(lngLastRow, "D")). _
SpecialCells(xlCellTypeBlanks).EntireRow.Delete SHift:=xlUp
End With

End Sub


Hope this helps! If so, let me know, click "YES" below.
--
Cheers,
Ryan


"Mikey" wrote:

Ryan responded with this code to highlight the cells. What code would delete
the rows?
------------------------
So you just want to "Select" the cell? Use this,

Sub Highlighter()

Dim lngLastRow As Long
Dim rng As Range

lngLastRow = Cells(Rows.Count, "D").End(xlUp).Row

For Each rng In Range("D1:D" & lngLastRow)
If IsEmpty(rng) Then
rng.Select
Exit For
End If
Next rng

End Sub
--
Cheers,
Ryan


--
Mickey


Gary''s Student

Selecting Blank Cells then deleting those rows
 
Perhaps:

Sub Highlighter()

Dim lngLastRow As Long
Dim rng As Range, rDelete As Range

lngLastRow = Cells(Rows.Count, "D").End(xlUp).Row

For Each rng In Range("D1:D" & lngLastRow)
If IsEmpty(rng) Then
If rDelete Is Nothing Then
Set rDelete = rng
Else
Set rDelete = Union(rDelete, rng)
End If
End If
Next rng
If rDelete Is Nothing Then
Else
rDelete.EntireRow.Delete
End If
End Sub
--
Gary''s Student - gsnu200909


"Mikey" wrote:

Ryan responded with this code to highlight the cells. What code would delete
the rows?
------------------------
So you just want to "Select" the cell? Use this,

Sub Highlighter()

Dim lngLastRow As Long
Dim rng As Range

lngLastRow = Cells(Rows.Count, "D").End(xlUp).Row

For Each rng In Range("D1:D" & lngLastRow)
If IsEmpty(rng) Then
rng.Select
Exit For
End If
Next rng

End Sub
--
Cheers,
Ryan


--
Mickey


Rick Rothstein

Selecting Blank Cells then deleting those rows
 
Assuming your cells in Column D have **data** in them so that your =""
condition means an empty cell, and **not formulas** that evaluate to "",
then give this "non looping" macro a try...

Sub DeleteEmptyCellsColumnC()
On Error Resume Next
Columns("D").SpecialCells(xlCellTypeBlanks).Entire Row.Delete
End Sub

--
Rick (MVP - Excel)


"Mikey" wrote in message
...
Ryan responded with this code to highlight the cells. What code would
delete
the rows?
------------------------
So you just want to "Select" the cell? Use this,

Sub Highlighter()

Dim lngLastRow As Long
Dim rng As Range

lngLastRow = Cells(Rows.Count, "D").End(xlUp).Row

For Each rng In Range("D1:D" & lngLastRow)
If IsEmpty(rng) Then
rng.Select
Exit For
End If
Next rng

End Sub
--
Cheers,
Ryan


--
Mickey




All times are GMT +1. The time now is 10:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com