+ Reply to Thread
Results 1 to 4 of 4

Compare Rows in 2 columns and count those that differ

Hybrid View

Tim3057 Compare Rows in 2 columns and... 03-12-2007, 08:44 AM
royUK Try Option Explicit Sub... 03-12-2007, 09:13 AM
Tim3057 Thanks... but I'm just after... 03-12-2007, 09:18 AM
Bryan Hessey Hi, try ... 03-15-2007, 08:58 AM
  1. #1
    Registered User
    Join Date
    01-12-2006
    Posts
    12

    Question Compare Rows in 2 columns and count those that differ

    Can I compare 2 columns (that are not side by side) and return a count of the number of times they differ?

    ie

    apples pears
    apples apples
    apples cherries
    apples apples

    would return a count of 2..?

    I need this to be a formula in one cell, with an answer showing in that cell.

    This may be basic stuff, but that's my level!!!

    Thanks,

    Tim

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try
    Option Explicit

    Sub count_differences()
        Dim rRng   As Range
        Dim rCl    As Range
        Dim lCnt   As Long
    
        Set rRng = Range(Cells(1, 1), Cells(Rows.Count, 1).End(xlUp))
        lCnt = 0
    
        For Each rCl In rRng
            If rCl.Value = rCl.Offset(0, 1).Value Then lCnt = lCnt + 1
        Next rCl
        MsgBox lCnt & " matches found"
    
    
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    01-12-2006
    Posts
    12
    Thanks... but I'm just after a single fomula to put in a cell on the spreadsheet.. I'm not trying to put it in a program - am I in the wrong forum?

  4. #4
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by Tim3057
    Thanks... but I'm just after a single fomula to put in a cell on the spreadsheet.. I'm not trying to put it in a program - am I in the wrong forum?
    Hi,

    try

    =COUNTA(A:A)-SUMPRODUCT(--(INDIRECT("A1:A"&COUNTA(A:A))=INDIRECT("B1:B"&COUNTA(A:A))))

    hth
    ---
    added,

    just read the original post, and the wording does not agree with the data sample given.

    What is meant by ' (that are not side by side)' in relation to where are they???
    ---
    Last edited by Bryan Hessey; 03-15-2007 at 09:04 AM.
    Si fractum non sit, noli id reficere.

+ 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