• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Delete User selected rows only if Col B ="1"

Cammandk

Member
I need a macro that will delete rows based on the below criteria:
The user can select a cell on a row or rows that they want to delete (therefore maybe multiple and non continuous rows)
The row can only be deleted if the value on the row in col B = "1".
Need some error handling if any of the cells selected don't equal the value in Col B.

Thanks
DK
 
OK.. I also love to work with less validation.. :)

check this one..

Code:
Sub DCode()
    Union(Range("B5"), Intersect(Columns("B"), Selection.EntireRow)). _
        ColumnDifferences(Range("B5")).EntireRow.Select 'Delete
End Sub

Assuming "B5" is a helper cell contain fixed value 0, and only consist 0 and in the column.

Just change the SELECT to DELETE after testing.. :)
 
Last edited:
This did select and delete the lines after testing - but where is the condition that B = 1 (or even "0" in your notes) to allow row delete
DK
 
Back
Top