+ Reply to Thread
Results 1 to 8 of 8

Thread: Comparing in excel

  1. #1
    Registered User
    Join Date
    02-13-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    4

    Comparing in excel

    Hi,
    I am new to this forum.
    I want to compare two columns, A and B, and print the values of A which are not existing in B to another column C.
    e.g

    A B C
    1 1 2
    2 3 4
    3 5
    4 7
    5 9

    As you can see, the values in C consists of values from A which are not there in B. So please help me how to do that in excel.

  2. #2
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Comparing in excel

    hello,

    You do not need macro for that
    use this code for set formula in C1 and then copy down as much as you will see data in column a and then use autofilter.
    Sub Makro1()
        Range("C1").FormulaR1C1 = "=IF(COUNTIF(C[-1],RC[-2])=0,RC[-2],"""")"
    End Sub
    Best Regards
    MaczaQ
    ---------------------------------------------------------------------------------------------------------------------------
    If you are satisfied with the solution(s) provided, please mark your thread as Solved
    If you are pleased with my answer consider to use the Scales icon to rate it - This way you will add me some reputation points ... thanks in advance.

  3. #3
    Registered User
    Join Date
    02-13-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Comparing in excel

    It is not working

  4. #4
    Valued Forum Contributor
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    412

    Re: Comparing in excel

    attach your workbook (with dummy data)
    Best Regards
    MaczaQ
    ---------------------------------------------------------------------------------------------------------------------------
    If you are satisfied with the solution(s) provided, please mark your thread as Solved
    If you are pleased with my answer consider to use the Scales icon to rate it - This way you will add me some reputation points ... thanks in advance.

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    Excel 2007
    Posts
    6,216

    Re: Comparing in excel

    Maybe this:
    Attached Files Attached Files
    "Relax. What is mind? No matter. What is matter? Never mind!"

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

    Re: Comparing in excel

    You can do this with VBA if you want
    Sub recipList()
    Dim arr1, arr2, recipArr, x, i As Long
    ReDim recipArr(i)
    arr1 = Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row).Value
    arr2 = Range("B1:B" & Cells(Rows.Count, "B").End(xlUp).Row).Value
    For Each x In arr1
        If IsError(Application.Match(x, arr2, 0)) Then
            ReDim Preserve recipArr(i)
            recipArr(i) = x
            i = i + 1
        End If
    Next
    For k = LBound(recipArr) To UBound(recipArr)
    Range("C" & k + 1) = recipArr(k)
    Next
    Range("C:C").SortSpecial SortMethod:=xlPinYin
    End Sub
    or
    Use the following formula in C1 and copy down
    =IF(ISERROR(MATCH(A1,$B$1:$B$5,0)),A1,"")
    Last edited by smuzoen; 02-13-2012 at 07:14 AM.
    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

  7. #7
    Registered User
    Join Date
    02-13-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Comparing in excel

    @maczaq : I can't attach the real file as it contains private data. Thats why I gave the example.
    @zbor : Thank you a lot. That is exactly what I wanted.

    But I had created a c++ program to do the same.

    @smuzoen : I don't have the VB compiler. But still thank you

    Thank you all for your valuable time.

  8. #8
    Registered User
    Join Date
    02-13-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Comparing in excel

    @zbor : I was thinking that can we have something create something like this

    A B C D E F G H
    1 Parrot 3 crow 2 Pideon 7 Tiger
    2 pidgeon 7 Tiger 4 peacock 11 cat
    3 crow 1 Parrot 5 eagle 21 mouse
    4 peacock 11 cat 6 vulture
    5 eagle 21 mouse
    6 vulture


    As we can see, we have 8 columns. Columns, A,B,C,D are input columns and the rest are output. Here A and B, C and D are mappings or pairs. Only A and C are to be compared, as I asked in my first post, and entries of A which are unavailable in C are to be output in E. But this time, the corresponding mapping of A i.e values of B are to be output in F also.

    Similarly, A and C are compared again and the entries of C which are unavailable in A are to be output in G. Also, the corresponding mapping of C i.e values of D are to be output in H.

    Can this be done? Anyone?

+ 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.2.0