+ Reply to Thread
Results 1 to 7 of 7

Search cell (external book) and delete row if found

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-16-2009
    Location
    NA
    MS-Off Ver
    MS Excel 2010
    Posts
    237

    Search cell (external book) and delete row if found

    Hi everyone! I have two workbooks, one is used for importing items to the site while the other is a monthly product list. In each of these I have a list of sku codes. I need a macro that will search each sku from the import to the entire product workbook. If it's found then delete the whole row from the product workbook. I have attached the examples below.

    Thanks for your time and help.
    Attached Files Attached Files
    Last edited by Zaeguzah; 09-26-2009 at 10:45 AM.

  2. #2
    Forum Contributor
    Join Date
    07-16-2009
    Location
    NA
    MS-Off Ver
    MS Excel 2010
    Posts
    237

    Re: Search cell (external book) and delete row if found

    Come on people.. can someone help?

  3. #3
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Search cell (external book) and delete row if found

    This will do it just change sheet names and workbook names to suit
    Sub Find_And_Copy()
        Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
        Dim FoundOne As Range, LookInR As Range, LookForR As Range, c As Range
        Dim nr3 As Long
        
        Application.ScreenUpdating = False
        Set ws1 = Sheets("Sheet4")
        Set ws2 = Sheets("Sheet5")
        Set ws3 = Sheets("Sheet6")
        Set LookInR = ws1.Range("A1").CurrentRegion
        Set LookForR = Range(ws2.Range("A2"), ws2.Range("A" & Rows.Count).End(xlUp))
        nr3 = ws3.Range("A" & Rows.Count).End(xlUp).Row + 1
        For Each c In LookForR
            With LookInR
                Set FoundOne = .Find(What:=c, LookAt:=xlPart)
                Do While Not FoundOne Is Nothing
                    FoundOne.EntireRow.Cut Destination:=ws3.Cells(nr3, 1)
                    nr3 = nr3 + 1
                    Set FoundOne = .FindNext
                Loop
            End With
        Next c
        Set ws1 = Nothing
        Set ws2 = Nothing
        Set ws3 = Nothing
        Set LookInR = Nothing: Set LookForR = Nothing
        Application.ScreenUpdating = True
    End Sub
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Search cell (external book) and delete row if found

    This will do the trick
    it ruff but will work?

    Sub Find_And_Copy()
        Dim FoundOne As Range, LookInR As Range, LookForR As Range, c As Range
         Application.ScreenUpdating = False
        Sheets("Sheet3").Select
      Windows("import.xls").Activate
      Sheets("sheet1").Range("A1:G500", Worksheets("Sheet1").Range("B561").End(xlUp)).Copy (Workbooks("products.xls").Sheets("Sheet3").Range("a1"))
       Windows("products.xls").Activate
     Sheets("general").Select
        Set LookForR = Range(Sheets("Sheet3").Range("A2"), Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp))
        Set LookInR = Range(Sheets(1).Range("c2"), Sheets(1).Range("c" & Rows.Count).End(xlUp))
         For Each c In LookForR
            With LookInR
                Set FoundOne = .Find(What:=c, LookAt:=xlPart)
                Do While Not FoundOne Is Nothing
                    FoundOne.EntireRow.Delete
                      Set FoundOne = .FindNext
                Loop
            End With
        Next c
        Set ws1 = Nothing
        Set ws2 = Nothing
        Set ws3 = Nothing
        Set LookInR = Nothing: Set LookForR = Nothing
        Application.ScreenUpdating = True
    End Sub
    Last edited by shg; 09-20-2009 at 01:01 PM. Reason: fix code tags

  5. #5
    Forum Contributor
    Join Date
    07-16-2009
    Location
    NA
    MS-Off Ver
    MS Excel 2010
    Posts
    237

    Re: Search cell (external book) and delete row if found

    Thanks pike! It works perfectly.

  6. #6
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Search cell (external book) and delete row if found

    Np Poroblems Alexander
    Can you please go back to your first post
    click edit
    then go advanced
    and change the post to SOLVED

  7. #7
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Search cell (external book) and delete row if found

    Hi Alexander
    Can you please go back to your first post
    click edit
    then go advanced
    and change the post prefix to SOLVED

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1