Delete Row when cell contains another cell text

Kell2Jam

New Member
Joined
May 10, 2020
Messages
33
Office Version
  1. 2013
Platform
  1. Windows
Hi, very new to this.

I need help with finding data from one sheet to finding data in another sheet and deleting that row.
I have had a lot of trouble with this and cant seem to crack it.
Can anyone help a formula?
 
See how you get on with the code below (make sure that there is at least one non-match when testing).

VBA Code:
Sub Test2()
    Dim myCell As Range, endCell As Long, destCell As Range
    Application.ScreenUpdating = False
    
    With Sheets("Last report")
        For Each myCell In .Range("A2:A" & .Range("A" & Rows.Count).End(xlUp).Row)
            If myCell.Value <> myCell.Offset(-1).Value Then
                endCell = .Columns("A").Find(myCell.Value, , xlValues, , xlByRows, xlPrevious).Row
                Set destCell = Sheets("Open PO's Report").Columns("A").Find(myCell.Value, , xlValues, , xlByRows, xlNext)
                If Not destCell Is Nothing Then Range(.Cells(myCell.Row, "A"), .Cells(endCell, "J")).Copy destCell
            End If
        Next
    End With
    
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
With the report i run there should never be any case where there is no match, is there anything i can do if there is not 1 non-match? or would it just be i would have to create a fake row cell every time?
 
Upvote 0
Did you try the last code posted? it won't matter if there are no non-matches when the code runs but it needs to be tested with a non-match as despite you stating
With the report i run there should never be any case where there is no match
you obviously did have one to get the error and so we need to make sure that the code is working in case you get the same again.
 
Upvote 0
Ok well i have ran the code and it works great, i havent gotten any bugs, i will run another test right now just to confirm, this test will have new data.

Thanks again and thank you for being so pacient.
 
Upvote 0
How would i alter this code to select for just a selected cell to a selected cell? as in if i wanted to add into the comments a number that matches the vendor name.
sheet to be copied from is "Contact list", cell column to match is "A" cell column to copy is "B"
Sheet to copy on is "Open PO's Report", Cell column to match "D", cell column to paste "I"
 
Upvote 0

Forum statistics

Threads
1,224,743
Messages
6,180,687
Members
452,994
Latest member
Janick

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