ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Conditoinal Row Delete (https://www.excelbanter.com/excel-programming/438819-conditoinal-row-delete.html)

Stephen

Conditoinal Row Delete
 
Hi Folks,

The code below works fine to hide the given row but I'd really like to
delete the row and i can't seem to make ".Cells(x, "F").EntireRow.Delete"
work for me.

LastRowOfData = .Cells(.Rows.Count, "F").End(xlUp).Row
For x = 11 To LastRowOfData - 1
If .Cells(x, "F").Value = 0 Then
.Cells(x, "F").EntireRow.Hidden = True
End If
Next

What am I missing?

TIA!

Ryan H

Conditoinal Row Delete
 
Give this a try. When you are deleting rows you want to start at the end of
the column and work up to the first row. Notice the "Step -1" syntax. Hope
this helps! If so, let me know, click "YES" below.

LastRowOfData = .Cells(.Rows.Count, "F").End(xlUp).Row
For x = LastRowOfData - 1 To 11 Step -1
If .Cells(x, "F").Value = 0 Then
.Rows(x).Delete Shift:=xlUp
End If
Next x
--
Cheers,
Ryan


"Stephen" wrote:

Hi Folks,

The code below works fine to hide the given row but I'd really like to
delete the row and i can't seem to make ".Cells(x, "F").EntireRow.Delete"
work for me.

LastRowOfData = .Cells(.Rows.Count, "F").End(xlUp).Row
For x = 11 To LastRowOfData - 1
If .Cells(x, "F").Value = 0 Then
.Cells(x, "F").EntireRow.Hidden = True
End If
Next

What am I missing?

TIA!


Stephen

Conditoinal Row Delete
 
worked like a charm. fantastic! thank you for the quick reply!

"Ryan H" wrote:

Give this a try. When you are deleting rows you want to start at the end of
the column and work up to the first row. Notice the "Step -1" syntax. Hope
this helps! If so, let me know, click "YES" below.

LastRowOfData = .Cells(.Rows.Count, "F").End(xlUp).Row
For x = LastRowOfData - 1 To 11 Step -1
If .Cells(x, "F").Value = 0 Then
.Rows(x).Delete Shift:=xlUp
End If
Next x
--
Cheers,
Ryan


"Stephen" wrote:

Hi Folks,

The code below works fine to hide the given row but I'd really like to
delete the row and i can't seem to make ".Cells(x, "F").EntireRow.Delete"
work for me.

LastRowOfData = .Cells(.Rows.Count, "F").End(xlUp).Row
For x = 11 To LastRowOfData - 1
If .Cells(x, "F").Value = 0 Then
.Cells(x, "F").EntireRow.Hidden = True
End If
Next

What am I missing?

TIA!



All times are GMT +1. The time now is 07:45 PM.

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