+ Reply to Thread
Results 1 to 3 of 3

Compare two columns, One to two match

Hybrid View

  1. #1
    Registered User
    Join Date
    08-15-2016
    Location
    Vaughan
    MS-Off Ver
    2010
    Posts
    2

    Compare two columns, One to two match

    Hello,

    I am trying to compare below two columns, one number from first column equals the sum of two numbers from second column. You may notice that 11.90=7.49+4.41
    Col 1 Col 2
    70.26 85.4
    69.17 7.49 <-
    93.98 4.41 <-
    11.90 <- 47.83
    17.06 77.80
    52.95 79.65


    below is the script I designed trying to highlight 11.90, but seems not working. Could someone take a look at this?

    Sub compare1to2()

    Dim i As Integer
    Dim j As Integer
    Dim k As Integer

    For i = 2 To 7
    For j = 2 To 6
    For k = j + 1 To 7
    If Range(i, 1).Value <> "" Then
    If Range(i, 1).Value = Range(j, 2).Value + Range(k, 2).Value Then
    Cells(i, 1).Interior.Color = RGB(255, 255, 0)

    Exit For
    End If
    End If
    Next k
    Next j
    Next i

    End Sub

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,498

    Re: Compare two columns, One to two match

    Try below code:
    PHP Code: 
    Sub test()
    Dim dict As Object
    Set dict 
    CreateObject("scripting.dictionary")
    Dim iAs Longrng As Variant
    For 2 To 6
        
    For 1 To 7
            dict
    .Add Cells(i1), Cells(i2) + Cells(j2)
        
    Next j
    Next i
    For 2 To 7
        
    For Each rng In dict.keys
            
    If Cells(i1) = dict(rngThen
            Cells
    (i1).Interior.Color RGB(2552550)
            
    End If
        
    Next rng
    Next i
    End Sub 
    Quang PT

  3. #3
    Registered User
    Join Date
    08-15-2016
    Location
    Vaughan
    MS-Off Ver
    2010
    Posts
    2

    Re: Compare two columns, One to two match

    Great! It works. Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. how to compare 2 columns, then add values that don't match
    By jousley in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-28-2016, 11:59 AM
  2. Compare two sets of columns and if row in each of the columns both match...
    By JDG94 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2016, 09:28 AM
  3. Macro to Compare two columns and publish sheet name in case columns dont match
    By adaws in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-06-2014, 01:21 PM
  4. Replies: 1
    Last Post: 10-04-2012, 02:31 PM
  5. Compare/Match two columns
    By heartstealer in forum Excel General
    Replies: 3
    Last Post: 11-08-2010, 07:37 AM
  6. Compare/Match two columns
    By heartstealer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-07-2010, 03:18 PM
  7. Can't use match to compare two columns
    By AC169 in forum Excel General
    Replies: 6
    Last Post: 04-16-2009, 04:58 PM

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