+ Reply to Thread
Results 1 to 12 of 12

delete rows if matching data not found on another worksheet

  1. #1
    Registered User
    Join Date
    05-09-2014
    MS-Off Ver
    Excel 2003
    Posts
    6

    delete rows if matching data not found on another worksheet

    The comparison needs to be done on unique id between sheet 1 and sheet 2. Both the sheet have id as a column. Need to compare this column. And delete the row in sheet 2 if there is no row for a particular id in sheet 1.

    Thanks!

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: delete rows if matching data not found on another worksheet

    Use countif() formula in a column and match the data with another sheet and apply filter and select 0 result and delete it


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: delete rows if matching data not found on another worksheet


    Hi,

    read VBA help of Find method and you can start to use Macro Recorder !

    Edit : too late, a guru yet answered …

  4. #4
    Registered User
    Join Date
    05-09-2014
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: delete rows if matching data not found on another worksheet

    thanks! I actually want a VBA code. Working on a Macro.

  5. #5
    Registered User
    Join Date
    05-09-2014
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: delete rows if matching data not found on another worksheet

    I'm new to VBA and unable o figure out what the code should be . can anyone help me with the code. I read up about Find method but not able to delete the rows that don't match.

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: delete rows if matching data not found on another worksheet

    We need a sample workbook for giving exact vba solution

    Attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  7. #7
    Registered User
    Join Date
    05-09-2014
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: delete rows if matching data not found on another worksheet

    Have uploaded a sample file. the objective is to delete the rows 2,7 and 8 from TCExecution worksheet as these test ids are not present in TCDetails Worksheet.

    Thanks for all your help!!!
    Attached Files Attached Files

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: delete rows if matching data not found on another worksheet

    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    Please Login or Register  to view this content.
    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button

  9. #9
    Registered User
    Join Date
    05-09-2014
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: delete rows if matching data not found on another worksheet

    when I run the macro it is opening the dialog box to select a file. and if click cancel, I get an error message and then a column with 1 is added. I already have the file open and with a few macros in it.

  10. #10
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: delete rows if matching data not found on another worksheet

    Two things you should remember while running the macro...

    1) You have to run it from the sheet on which the deletion needs to be done.

    2) Check the Comparison sheetname (i.e.) in the sample file the you named it as TCDetails so check whether any sheet exist with that name. If not then the macro will throw errors like this....

    If your name of the comparison sheet is different then find this word TCDetails in the provided macro and replace it with your actual sheet name

  11. #11
    Registered User
    Join Date
    05-09-2014
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: delete rows if matching data not found on another worksheet

    the sheet name is the same and ran the macro from the sheet TCExecution where the deletion needs to be done. still getting this issue.

  12. #12
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: delete rows if matching data not found on another worksheet

    I added the code in your sample file and attaching the file for your reference. Run the code from the Sheet2 sheet.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA Code to Delete Rows in One Target Worksheet Based on Value Found in One Column
    By Aimeeeshaw in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-16-2013, 12:15 PM
  2. [SOLVED] Mark or Delete Rows based on Matching Multiple Criteria in another worksheet
    By clearbluez in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-11-2012, 02:38 PM
  3. Compare data in selected columns and delete all matching rows
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-06-2011, 09:35 AM
  4. Replies: 16
    Last Post: 08-02-2010, 12:07 PM
  5. delete worksheet if found
    By mattfaust in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-30-2006, 11:33 AM

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