Delete rows if cells has any value

aayaanmayank

Board Regular
Joined
Jul 20, 2018
Messages
157
Hi Can any one help me on this?

Based on ID match, if first cell and 2nd cell has any value then delete entire row. also if any of cell has value then it should not delete both the rows which contains same ID. i have written below code but it is not working properly.
MY data

ID

<tbody>
</tbody>
CODE

<tbody>
</tbody>
419191389

<tbody>
</tbody>
DFGHJK

<tbody>
</tbody>
419191389

<tbody>
</tbody>
DFGHJK

<tbody>
</tbody>
13393262

<tbody>
</tbody>
LCPD

<tbody>
</tbody>
13393262

<tbody>
</tbody>
16466396

<tbody>
</tbody>
LCPC

<tbody>
</tbody>
16466396

<tbody>
</tbody>
LCPC

<tbody>
</tbody>
24666862

<tbody>
</tbody>
24666862

<tbody>
</tbody>
26215556

<tbody>
</tbody>
LCPD

<tbody>
</tbody>
26215556

<tbody>
</tbody>
38694658

<tbody>
</tbody>
LCPC

<tbody>
</tbody>
38694658

<tbody>
</tbody>
LCPC

<tbody>
</tbody>

<tbody>
</tbody>
Code:
Sub may2()

Application.ScreenUpdating = False
Application.CutCopyMode = False
Set SHDQ = ThisWorkbook.Worksheets("U Assign DQ Team")


lastrow1 = SHDQ.Range("B" & Rows.Count).End(xlUp).Row


SHDQ.Activate


For O = 2 To lastrow1


    If SHDQ.Cells(O, "B").Value = SHDQ.Cells(O + 1, "B").Value Then
    If SHDQ.Cells(O, "R").Value = True And SHDQ.Cells(O + 1, "R").Value = True Then
       End If
       
       MsgBox ("DELET")
       End If
             
    Next




End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
aayaanmayank,

You might consider the following...

Code:
Sub may2()
Application.ScreenUpdating = False
Application.CutCopyMode = False

Set SHDQ = ThisWorkbook.Worksheets("U Assign DQ Team")
lastrow1 = SHDQ.Range("B" & Rows.Count).End(xlUp).Row
SHDQ.Activate

For O = lastrow1 To 2 Step -1
    If SHDQ.Cells(O, "B").Value = SHDQ.Cells(O - 1, "B").Value And _
        SHDQ.Cells(O, "R").Value = SHDQ.Cells(O - 1, "R").Value And SHDQ.Cells(O, "R").Value = "" Then
            MsgBox "Delete Row " & O & ", " & O - 1
    ElseIf SHDQ.Cells(O, "B").Value = SHDQ.Cells(O - 1, "B").Value And _
        SHDQ.Cells(O, "R").Value = SHDQ.Cells(O - 1, "R").Value Then
            MsgBox "Delete Row " & O
    ElseIf SHDQ.Cells(O, "B").Value = SHDQ.Cells(O - 1, "B").Value And _
        SHDQ.Cells(O, "R").Value = "" Then
            MsgBox "Delete Row " & O
    ElseIf SHDQ.Cells(O, "B").Value = SHDQ.Cells(O - 1, "B").Value And _
        SHDQ.Cells(O - 1, "R").Value = "" Then
            MsgBox "Delete Row " & O - 1
    End If
Next
End Sub

Cheers,

tonyyy
 
Upvote 0

Forum statistics

Threads
1,215,487
Messages
6,125,075
Members
449,205
Latest member
Healthydogs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top