Results 1 to 2 of 2

Thread: DELETING ROWS IN SPREADSHEET BASED ON CRITERIA IN ANOTHER SHEET

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    2
    Rep Power
    0

    DELETING ROWS IN SPREADSHEET BASED ON CRITERIA IN ANOTHER SHEET

    I have a spreadsheet which has a single column with a few rows of names. I have a second spreadsheet which has 4 columns. The first column contains names. There may be multiple rows with the same name in the first column. I need to keep only those rows in the second spreadsheet where the names in first column match the names in the first spreadsheet. The other rows must be deleted.

    Thanks for your help.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    8
    Rep Power
    0
    Try the code below, change the sheetnames to suit.

    Code:
    Sub CCCCB()
        Dim c As Range, DeleteRange As Range
        For Each c In Sheets("Sheet2").Range("A2:A" & Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row)
            If WorksheetFunction.CountIf(Sheets("Sheet1").Range("A2:A" & Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row), c) = 0 Then
                If DeleteRange Is Nothing Then
                    Set DeleteRange = Rows(c.Row)
                Else
                    Set DeleteRange = Union(DeleteRange, Rows(c.Row))
                End If
            End If
        Next
        DeleteRange.Delete
    End Sub
    Using Office 2010
    Quite often have to save as '97-
    2003 for other users

Similar Threads

  1. VBA To Delete Rows Based On Value Criteria In A Column
    By jffryjsphbyn in forum Excel Help
    Replies: 1
    Last Post: 08-15-2013, 12:45 PM
  2. Replies: 6
    Last Post: 08-14-2013, 04:25 PM
  3. Import Export Spreadsheet Macro Action Specific Sheet
    By Portucale in forum Access Help
    Replies: 3
    Last Post: 08-06-2013, 07:42 AM
  4. Replies: 4
    Last Post: 07-08-2013, 05:36 PM
  5. Deleting blank rows
    By Rasm in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 04-14-2011, 03:14 AM

Posting Permissions

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