+ Reply to Thread
Results 1 to 4 of 4

Compare two columns to sheet3

Hybrid View

  1. #1
    Registered User
    Join Date
    09-11-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    6

    Compare two columns to sheet3

    In the workbook there are 2 sheets
    1)Postawardlog and 2) budget posted in EIS
    Our task:
    ACCOUNT in sheet1 and Projectid in sheet2, TOTAL in sheet1 and Amount in sheet2 are columns which needs to be compared. We need to display o/p in sheet3 for only which are not matching. Please see the project1 word document attached for details. I am also attaching the code which i have.
    I am trying it and not able to solve. please send me the macro code as reply or mail me at [email protected]. Thank you in advance.
    I am posting the code which i have but it is having some errors.
    Sub combine_data()
    Dim DestCell As Range, SourcE1 As Range, sourcE2 As Range, FirstCell As Range, cc As Range, ffound As Boolean
    
    Set SourcE1 = Sheets(1).Range("a2") ' 1st data cell of 1st list
    Set sourcE2 = Sheets(2).Range("a2") ' 1st data cell of 2nd list
    Set DestCell = Sheets(3).Range("a2") 'cell to copy the combined table to
    Set FirstCell = DestCell
    
    Do While SourcE1 <> ""
        DestCell = SourcE1
        DestCell.Offset(0, 1) = SourcE1.Offset(0, 1)
        Set DestCell = DestCell.Offset(1, 0)
        Set SourcE1 = SourcE1.Offset(1, 0)
    Loop
    
    Do While sourcE2 <> ""
        For Each cc In Range(FirstCell, DestCell)
            ffound = False
            If cc = sourcE2 Then
                cc.Offset(0, 2) = sourcE2.Offset(0, 1)
                ffound = True
                GoTo nxt
            End If
        Next cc
        If ffound = False Then
            DestCell = sourcE2
            DestCell.Offset(0, 2) = sourcE2.Offset(0, 1)
            Set DestCell = DestCell.Offset(1, 0)
        End If
    nxt:
    Set sourcE2 = sourcE2.Offset(1, 0)
    Loop
    
    For Each cc In Range(FirstCell, DestCell.Offset(-1, 0))
        cc.Offset(0, 3).FormulaR1C1 = _
            "=IF(RC[-1]="""",""not present in sheet 2"",IF(RC[-2]="""",""not present in sheet 1"",IF(RC[-2]<>RC[-1],""values mismatch"","""")))"
    Next cc
        
    End Sub
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    927

    Re: Compare two columns to sheet3

    Cross-post:
    http://www.vbaexpress.com/forum/show...d-on-condition
    http://www.mrexcel.com/forum/excel-q...condition.html
    http://www.excelfox.com/forum/f2/com...ondition-1449/

  3. #3
    Registered User
    Join Date
    09-11-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Compare two columns to sheet3

    Hi rollis,
    I think i can post same post in many forums. is that right????

  4. #4
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    927

    Re: Compare two columns to sheet3

    Yes you can, but first read and understand the rules of the Forums and then you will realize why you should not.
    Last edited by rollis13; 09-13-2013 at 06:48 PM.

+ 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. [SOLVED] Compare two lists in Sheet 1 & 2 Column A, then combine the match adjacent cells in sheet3
    By Raulus in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-06-2013, 08:51 AM
  2. Replies: 5
    Last Post: 08-29-2012, 03:08 AM
  3. How to populate cell A1 of a sheet3 without explicitly selecting sheet3 first
    By teachMeExcel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-27-2009, 01:07 AM
  4. Excel 2007 : Compare: Sheet1 - Sheet2 into Sheet3
    By vbjohn in forum Excel General
    Replies: 3
    Last Post: 07-17-2009, 03:33 PM
  5. How to copy some columns from sheet1 to sheet2 or sheet3
    By wlarson in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-30-2007, 08:58 AM

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