• 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
 
Need some error handling .....

Some !!!! .. DK, we need to handle atleast 100+ validations to check, if we dont have exact picture of the excel file with expected output.

Please upload sample file with expected output...
 
I've attached a sample section of a worksheet.
I don't understand why there may be so many validations to check?
Thanks
DK
 

Attachments

  • Delete rows.xlsx
    19.9 KB · Views: 5
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
 
i think.
the code is deleting only selected cell with column B as 1..
can you please recheck!
 
Back
Top