ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to Delete rows with blank or specific value in a Macro ? (https://www.excelbanter.com/excel-programming/419398-how-delete-rows-blank-specific-value-macro.html)

glenn

How to Delete rows with blank or specific value in a Macro ?
 
I would like to know if there's a way, within a macro, to delete rows within
a specific range if the first cell in the row is either empty or has a
specific value, such as 'False'.

Per Jessen

How to Delete rows with blank or specific value in a Macro ?
 
This should do it:

Sub test()
Dim TargetRange As Range
Set TargetRange = Range("A10:D15") ' Change to suit desired range
TargetCol = TargetRange.Column
FirstRow = TargetRange.Row
LastRow = TargetRange.Rows.Count + FirstRow - 1
For r = LastRow To FirstRow Step -1
If Cells(r, TargetCol).Value = "" Or _
Cells(r, TargetCol).Value = "False" Then
Rows(r).Delete
End If
Next
End Sub
"Glenn" skrev i meddelelsen
...
I would like to know if there's a way, within a macro, to delete rows
within
a specific range if the first cell in the row is either empty or has a
specific value, such as 'False'.




All times are GMT +1. The time now is 02:28 PM.

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