+ Reply to Thread
Results 1 to 13 of 13

[VBA] Comparing two columns and pasting the difference into a third column

Hybrid View

  1. #1
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: [VBA] Comparing two columns and pasting the difference into a third column

    I get your logic now - essentially 2 comparisons are required and an array constructed from the comparisons. If you wanted to just construct a unique list in an array you could use Scripting Dictionary and Keys however your request is different. Try this
    Sub compList()
    Dim newList, a, x As Long, fnd As Boolean
    ReDim newList(x)
    With Range("A1")
    a = .CurrentRegion
    End With
    x = 0
    For k = 1 To UBound(a)
    For t = 1 To UBound(a)
    If a(k, 1) = a(t, 2) Then
    fnd = True
    Exit For
    End If
    Next
    If fnd = False Then
    ReDim Preserve newList(x)
    newList(x) = a(k, 1)
    x = x + 1
    End If
    fnd = False
    Next
    For k = 1 To UBound(a)
    For t = 1 To UBound(a)
    If a(k, 2) = a(t, 1) Then
    fnd = True
    Exit For
    End If
    Next
    If fnd = False Then
    ReDim Preserve newList(x)
    newList(x) = a(k, 2)
    x = x + 1
    End If
    fnd = False
    Next
    For k = LBound(newList) To UBound(newList)
    Range("C" & k + 1) = newList(k)
    Next
    End Sub
    See attachment for example.
    Attached Files Attached Files
    Hope this helps.
    Anthony
    Pack my box with five dozen liquor jugs
    PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated?

+ 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