Consulting

Results 1 to 3 of 3

Thread: Extracting intersecting values from two or more ranges

  1. #1
    VBAX Regular
    Joined
    Aug 2017
    Posts
    57
    Location

    Post Extracting intersecting values from two or more ranges

    I am looking for a formula or code to extract intersecting numbers from two or more range of values. Lets say, I have values in A1 ( 1,2,3,4,5) and B1 (1,2,3) and C1 (2,3). Is it possible to get the intersecting values (2,3) of these three groups in D1? In this example, I used three groups but there can be more. Thanks.

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Option Explicit
    
    
    Function CommonValue(r As Range) As String
        Dim d As Object
        Dim c As Range
        Dim i As Long, k As Long
        Dim tmp, v
        
        Set d = CreateObject("scripting.dictionary")
        
        For Each c In r
            d(d.Count + 1) = Split(c.Value, ",")
        Next
        
        tmp = d(1)
        
        For i = 2 To d.Count
            v = tmp
            For k = 0 To UBound(d(i))
                v = Filter(v, d(i)(k), False)
            Next
            For k = 0 To UBound(v)
                tmp = Filter(tmp, v(k), False)
            Next
        Next
    
    
        CommonValue = Join(tmp, ",")
        
    End Function

  3. #3
    VBAX Regular
    Joined
    Aug 2017
    Posts
    57
    Location
    Hi Mana, thanks for your solution. It works perfectly!

Tags for this Thread

Posting Permissions

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