+ Reply to Thread
Results 1 to 17 of 17

Deleting Rows based on matching values in column A, in two different worksheets

  1. #1
    Registered User
    Join Date
    07-08-2012
    Location
    NA
    MS-Off Ver
    Excel Starter/Sometimes Excel 2010
    Posts
    33

    Deleting Rows based on matching values in column A, in two different worksheets

    I am comparing column A of two different worksheets. I want keep all of the column A values that are in both sheets. I want to delete the rows of those values in sheet2 that do no appear in sheet1. Can someone please help?

    Thank you!
    Last edited by Insert Name; 01-12-2013 at 02:59 PM.

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Deleting Rows based on matching values in column A, in two different worksheets

    This should do it

    Please Login or Register  to view this content.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  3. #3
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Deleting Rows based on matching values in column A, in two different worksheets

    This maybe faster

    Please Login or Register  to view this content.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Deleting Rows based on matching values in column A, in two different worksheets

    Hi,

    Try this - what do you want to do about duplicates in Sheet2??

    Please Login or Register  to view this content.
    Directions for running the routine(s) just supplied

    Copy the code to the clipboard

    Press ALT + F11 to open the Visual Basic Editor.

    Open a macro-enabled Workbook or save your Workbook As Macro-Enabled

    Select “Module” from the Insert menu

    Type "Option Explicit" then paste the code into the white space on the right

    With the cursor between Sub and End Sub press F5 (F8 to Single Step)

    OR

    Press ALT + Q to close the code window.

    Press ALT + F8 then double click on the macro name
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  5. #5
    Registered User
    Join Date
    07-08-2012
    Location
    NA
    MS-Off Ver
    Excel Starter/Sometimes Excel 2010
    Posts
    33

    Re: Deleting Rows based on matching values in column A, in two different worksheets

    Quote Originally Posted by xladept View Post
    Hi,

    Try this - what do you want to do about duplicates in Sheet2??

    Please Login or Register  to view this content.
    Directions for running the routine(s) just supplied

    Copy the code to the clipboard

    Press ALT + F11 to open the Visual Basic Editor.

    Open a macro-enabled Workbook or save your Workbook As Macro-Enabled

    Select “Module” from the Insert menu

    Type "Option Explicit" then paste the code into the white space on the right

    With the cursor between Sub and End Sub press F5 (F8 to Single Step)

    OR

    Press ALT + Q to close the code window.

    Press ALT + F8 then double click on the macro name
    There should not be duplicates in the sheet I use this in with. Does sheet2 have duplicates?

  6. #6
    Registered User
    Join Date
    07-08-2012
    Location
    NA
    MS-Off Ver
    Excel Starter/Sometimes Excel 2010
    Posts
    33

    Re: Deleting Rows based on matching values in column A, in two different worksheets

    If I wanted to do this for two excell documents, the first of which has 20 tabs, the second has 23. How would I do this?
    If sheet1 has the list to compare from, and every sheet after that has the column A to delete rows from.

  7. #7
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Deleting Rows based on matching values in column A, in two different worksheets

    This should do it

    Please Login or Register  to view this content.

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Deleting Rows based on matching values in column A, in two different worksheets

    If I wanted to do this for two excell documents, the first of which has 20 tabs, the second has 23. How would I do this?
    If sheet1 has the list to compare from, and every sheet after that has the column A to delete rows from.
    You need to have the Excel Documents Active then just play this:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-08-2012
    Location
    NA
    MS-Off Ver
    Excel Starter/Sometimes Excel 2010
    Posts
    33

    Re: Deleting Rows based on matching values in column A, in two different worksheets

    How do you make excel document active?

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Deleting Rows based on matching values in column A, in two different worksheets

    Have the document "up" the active one is the one that comes up when you click on Excel. In other words - while your looking at the Workbook in question - the one with 20 or 23 tabs! The code doesn't need to be in the active book but it must be in the module of a macro-enabled book (for 2007 and 2010 which you have).

  11. #11
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Deleting Rows based on matching values in column A, in two different worksheets

    Will the list be in both workbooks? In other words will each workbook have its own list to ompare with he other sheets?

  12. #12
    Registered User
    Join Date
    07-08-2012
    Location
    NA
    MS-Off Ver
    Excel Starter/Sometimes Excel 2010
    Posts
    33

    Re: Deleting Rows based on matching values in column A, in two different worksheets

    Yes, but I will only open one of the excel documents at a time is this ok?

  13. #13
    Registered User
    Join Date
    07-08-2012
    Location
    NA
    MS-Off Ver
    Excel Starter/Sometimes Excel 2010
    Posts
    33

    Re: Deleting Rows based on matching values in column A, in two different worksheets

    In the book I attached column A has our numbers in the book I am working with column A has seven numbers does this make a difference?
    I should add that when I run the macros many of the unwanted cells are deleted, and those in sheet one column A do appear in other sheets. But some that do not appear in column A sheet one say in the other sheets. I think it might have to do with the numbers of each value in column A.

    Thoughts.

    Overall seems to be working well.

  14. #14
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Deleting Rows based on matching values in column A, in two different worksheets

    Pace this in a separate workbook. The workbooks that your wanting to remove rows from must be opened before running macro.

    Also change this part of the code to the names of your workooks

    Please Login or Register  to view this content.


    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    07-08-2012
    Location
    NA
    MS-Off Ver
    Excel Starter/Sometimes Excel 2010
    Posts
    33

    Re: Deleting Rows based on matching values in column A, in two different worksheets

    If the last column in some rows are different does it matter? I want to see if I can get this to work for a similar situations with data. Where the number of column changes?
    Last edited by Insert Name; 01-11-2013 at 07:43 PM.

  16. #16
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Deleting Rows based on matching values in column A, in two different worksheets

    Nope that wont matter

  17. #17
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Deleting Rows based on matching values in column A, in two different worksheets

    Well, when I ran it Sheet2 had more rows than Sheet1 - I assumed that they were duplicates since I traversed every cell in Sheet2 Row A???????

+ 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