ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to delete a row based on a condition (https://www.excelbanter.com/excel-programming/421438-how-delete-row-based-condition.html)

Ya

how to delete a row based on a condition
 
how to delete a row based on a condition

Noob McKnownowt

how to delete a row based on a condition
 


"ya" wrote:

how to delete a row based on a condition


If you could provide us with a little more information that would help, but
a general answer would be somethin like;

Sub DelRow()

Dim Rng as Range
Dim Cell as Range

set Rng = Sheet("the sheet you want to check").Range(The range on the sheet
you want to search. i.e. "D:D")

For Each Cell in Rng
If Cell.Value = "what you want to search for" Then
Cell.EntireRow.Delete
End If
Next Cell

End Sub

HTH,

The Noob

Mike

how to delete a row based on a condition
 
Private Sub deleterows()
Dim rng As Range
Dim i As Long

Set rng = ActiveSheet.Range(Cells(1, "A"), Cells(Rows.Count, "A").End(xlUp))

'Work backwards from bottom to top when deleting rows
'This will delete the row if cell value = 0
'change 0 to your needs
With rng
For i = .Rows.Count To 1 Step -1
If .Cells(i) = 0 Then
.Cells(i).EntireRow.Delete
End If
Next i
End With
End Sub

"ya" wrote:

how to delete a row based on a condition



All times are GMT +1. The time now is 04:43 AM.

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