ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete Line (https://www.excelbanter.com/excel-programming/428202-delete-line.html)

Shawn

Delete Line
 
I need the code below altered so it deletes the entire row the blank cell is
in.

Dim xRange As Range
Dim xCell As Range

For Each xCell In Sheets("CDPTR").Range("A2:A25")
If xCell.Value = 0 Then
If xRange Is Nothing Then
Set xRange = xCell
Else
Set xRange = Union(xRange, xCell)
End If
End If
Next xCell
xRange.Delete Shift:=xlup


--
Thanks
Shawn

Jacob Skaria

Delete Line
 
Replace the last line of the code with

xRange.EntireRow.Delete

If this post helps click Yes
---------------
Jacob Skaria


"Shawn" wrote:

I need the code below altered so it deletes the entire row the blank cell is
in.

Dim xRange As Range
Dim xCell As Range

For Each xCell In Sheets("CDPTR").Range("A2:A25")
If xCell.Value = 0 Then
If xRange Is Nothing Then
Set xRange = xCell
Else
Set xRange = Union(xRange, xCell)
End If
End If
Next xCell
xRange.Delete Shift:=xlup


--
Thanks
Shawn


Per Jessen[_2_]

Delete Line
 
Hi

Use this:

xRange.EntireRow.Delete

Regards,
Per

On 8 Maj, 14:03, Shawn wrote:
I need the code below altered so it deletes the entire row the blank cell is
in.

* * * * * * * * * * Dim xRange As Range
* * * * * * * * * * Dim xCell As Range

* * * * * * * * * * For Each xCell In Sheets("CDPTR").Range("A2:A25")
* * * * * * * * * * * * If xCell.Value = 0 Then
* * * * * * * * * * * * * * If xRange Is Nothing Then
* * * * * * * * * * * * * * * * Set xRange = xCell
* * * * * * * * * * * * * * Else
* * * * * * * * * * * * * * * * Set xRange = Union(xRange, xCell)
* * * * * * * * * * * * * * End If
* * * * * * * * * * * * End If
* * * * * * * * * * Next xCell
* * * * * * * * * * xRange.Delete Shift:=xlup

--
Thanks
Shawn



Shawn

Delete Line
 
Great. That works. I was using this code and it wasn't working:

Range("xRange" & ActiveCell.Row).EntireRow.Delete Shift:=xlUp

--
Thanks
Shawn


"Jacob Skaria" wrote:

Replace the last line of the code with

xRange.EntireRow.Delete

If this post helps click Yes
---------------
Jacob Skaria


"Shawn" wrote:

I need the code below altered so it deletes the entire row the blank cell is
in.

Dim xRange As Range
Dim xCell As Range

For Each xCell In Sheets("CDPTR").Range("A2:A25")
If xCell.Value = 0 Then
If xRange Is Nothing Then
Set xRange = xCell
Else
Set xRange = Union(xRange, xCell)
End If
End If
Next xCell
xRange.Delete Shift:=xlup


--
Thanks
Shawn



All times are GMT +1. The time now is 06:14 AM.

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