Results 1 to 10 of 13

Thread: Delete List Contain Matching from Second List

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member Rajan_Verma's Avatar
    Join Date
    Sep 2011
    Posts
    81
    Rep Power
    14

    Delete List Contain Matching from Second List

    Hi,

    What would be your approach to do this job

    Suppose you have 2 List, and you need to remove List2 contents from List1 , here is better code to accomplish this job , By using dictionary i just tried to make this process fast

    You just need to define two name ranges to use this Code,

    1st Cell of List1 = "RngRange"
    1st Cell of List2 ="MapDelete"

    Code:
    Sub ExcludeFromList()
     
        Dim objDicMap As Object
        Dim VarArrData
        Dim VarArrResult
        Dim rngCell   As Range
        Dim lngCOunt As Long  
    
        VarArrData = Intersect(Range(“rngRange”).CurrentRegion, Range(“rngRange”).CurrentRegion.Offset(1))
        Set objDicMap = CreateObject(“Scripting.Dictionary”)    ‘ Dictionary Object get Mapping
    
        ’Filling Dictionary
        For Each rngCell In Intersect(Range(“MapDelete”).CurrentRegion, Range(“MapDelete”).CurrentRegion.Offset(1))
            If Not objDicMap.exists(rngCell.Value) Then objDicMap.Add rngCell.Value, rngCell.Value
        Next rngCell
    
        ’Filling Result Array From Data List which would not Include Mapping Data
    
        For lngCOunt = LBound(VarArrData) To UBound(VarArrData)
            If Not objDicMap.exists(VarArrData(lngCOunt, 1)) Then
                If Not IsArray(VarArrResult) Then
                    ReDim VarArrResult(0 To 0)
                    VarArrResult(0) = VarArrData(lngCOunt, 1)
                Else
                    ReDim Preserve VarArrResult(UBound(VarArrResult) + 1)
                    VarArrResult(UBound(VarArrResult)) = VarArrData(lngCOunt, 1)
                End If
            End If
        Next lngCOunt
        ‘Clear Old List
        Range(“rngRange”).CurrentRegion.Offset(1).Clear
        ‘Replace with new list
        Range(“rngRange”).Offset(1).Resize(UBound(VarArrResult)).Value = Application.Transpose(VarArrResult)
        Set objDicMap = Nothing
        Set rngCell = Nothing
    
    End Sub
    Thanks for Reading

    Rajan.
    Last edited by Rajan_Verma; 10-04-2012 at 11:15 PM.

Similar Threads

  1. Exclude Contents From List :
    By Rajan_Verma in forum Rajan Verma's Corner
    Replies: 16
    Last Post: 06-08-2013, 12:29 AM
  2. Get Random List :
    By Rajan_Verma in forum Rajan Verma's Corner
    Replies: 0
    Last Post: 06-06-2013, 07:53 PM
  3. Auto Unique List
    By r_know in forum Excel Help
    Replies: 8
    Last Post: 07-19-2012, 09:28 PM
  4. Create list with arrays
    By PcMax in forum Excel Help
    Replies: 2
    Last Post: 04-10-2012, 11:05 PM
  5. List Of All Files In A Folder
    By Excel Fox in forum Excel Help
    Replies: 2
    Last Post: 10-27-2011, 09:10 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
  •