Results 1 to 4 of 4

Macro deleting all, not just the duplicates

Threaded View

JamesT1 Macro deleting all, not just... 04-29-2019, 08:40 AM
JLGWhiz Re: Macro deleting all, not... 04-29-2019, 09:38 AM
JamesT1 Re: Macro deleting all, not... 04-29-2019, 12:02 PM
JLGWhiz Re: Macro deleting all, not... 04-29-2019, 12:59 PM
  1. #1
    Forum Contributor
    Join Date
    08-04-2008
    Location
    West Calder, Scotland
    MS-Off Ver
    365
    Posts
    430

    Macro deleting all, not just the duplicates

    Good afternoon all

    I have a workbook with several sheet... two of which are called 'Data' and 'Add Driver', both have headers.

    I'm looking at comparing the information in column B in both sheets,,, when it finds a duplicate I'm looking at deleting the row in the sheet 'Add Driver', the ranges, including headers, start in Row 8 on the 'Data sheet and Row 1 on the 'Add Driver Sheet'

    I have been working with this macro but the closest I can get it, is for it to delete everything, except the headers in the 'Add Driver' sheet

    Any help would be much appreciated

    Many thanks

    JT

    Sub Add_Driver()
    
    Dim LR As Integer, x As Integer
    
    UnprotectMain
    
    LR = ThisWorkbook.Sheets("Add Driver").Cells(Rows.Count, 2).End(xlUp).Row
    Application.ScreenUpdating = False
    For x = LR To 2 Step -1
        If Application.WorksheetFunction.CountIf(Sheets("Data").Range("B9:B5000"), Sheets("Add Driver").Cells(x, 2).Value) = 0 Then
            Sheets("Add Driver").Rows(x).EntireRow.Delete
        End If
    Next x
    
    Application.ScreenUpdating = True
    
    End Sub
    Last edited by JamesT1; 04-29-2019 at 12:02 PM. Reason: Solved

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro deleting duplicates between 2 sheets
    By mamachrissy1028 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-12-2015, 04:50 PM
  2. [SOLVED] Macro For Deleting Duplicates, Comparing Rows and Retaining Minimum Value
    By banawaja in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-08-2014, 04:45 AM
  3. Macro Code - Deleting Duplicates based on same cell value and date comparison
    By Desree86 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-13-2014, 04:01 PM
  4. Replies: 0
    Last Post: 02-13-2013, 04:35 PM
  5. [SOLVED] Macro for finding duplicates then deleting the row
    By adamj1910 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-17-2012, 04:11 AM
  6. Deleting Duplicates-find out a way to delete duplicates
    By sighlent1 in forum Excel General
    Replies: 2
    Last Post: 04-19-2011, 10:17 AM
  7. Deleting duplicates in a macro
    By tryaz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2009, 03:31 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