+ Reply to Thread
Results 1 to 19 of 19

Compare cell by cell in sheets

Hybrid View

slashdot Compare cell by cell in sheets 08-29-2011, 02:42 AM
royUK Re: Compare cell by cell in... 08-29-2011, 02:47 AM
slashdot Re: Compare cell by cell in... 08-29-2011, 02:53 AM
slashdot Re: Compare cell by cell in... 08-29-2011, 02:55 AM
gjlindn Re: Compare cell by cell in... 08-29-2011, 03:18 AM
gjlindn Re: Compare cell by cell in... 09-01-2011, 10:43 PM
slashdot Re: Compare cell by cell in... 08-29-2011, 04:53 AM
slashdot Re: Compare cell by cell in... 08-29-2011, 11:57 AM
slashdot Re: Compare cell by cell in... 09-01-2011, 09:16 PM
slashdot Re: Compare cell by cell in... 09-01-2011, 11:29 PM
slashdot Re: Compare cell by cell in... 09-01-2011, 11:42 PM
tigertiger Re: Compare cell by cell in... 09-02-2011, 12:12 AM
slashdot Re: Compare cell by cell in... 09-02-2011, 12:15 AM
slashdot Re: Compare cell by cell in... 09-02-2011, 12:19 AM
slashdot Re: Compare cell by cell in... 09-02-2011, 12:33 AM
gjlindn Re: Compare cell by cell in... 09-02-2011, 12:59 AM
slashdot Re: Compare cell by cell in... 09-02-2011, 02:07 AM
gjlindn Re: Compare cell by cell in... 09-02-2011, 03:34 PM
tigertiger Re: Compare cell by cell in... 09-03-2011, 08:22 AM
  1. #1
    Registered User
    Join Date
    08-23-2011
    Location
    East
    MS-Off Ver
    Excel 2007
    Posts
    60

    Compare cell by cell in sheets

    hi all..i had a query regarding comparing cells which contains text in col A in worksheet 1 and cells with text in col A in worksheet2...i want a vba code to run for,compare each cell by cell in worksheet 1 with the cells in worksheet2 and copy,paste the matched cells in a new sheet named "copied" data....

    P.S. worksheet1 contains repetitive text in colA

    attached a sample worksheet.
    Attached Files Attached Files
    Last edited by slashdot; 08-29-2011 at 02:54 AM.

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

    Re: Compare cell by cell in sheets

    It would be much faster to use formulas
    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
    08-23-2011
    Location
    East
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Compare cell by cell in sheets

    hmmm.its ok but i want to learn vba.i could not loop each cell perfectly.so was looking for the same....pls help me..

  4. #4
    Registered User
    Join Date
    08-23-2011
    Location
    East
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Compare cell by cell in sheets

    i think i need to use compstr in column A of worksheet 1 with column A of worksheet 2 cell by cell....

  5. #5
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Compare cell by cell in sheets

    Could you update your example to include what you want the output ("Copied" worksheet) to look like?
    -Greg If this is helpful, pls click Star icon in lower left corner

  6. #6
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Compare cell by cell in sheets

    Quote Originally Posted by gjlindn View Post
    Could you update your example to include what you want the output ("Copied" worksheet) to look like?
    Sorry slashdot. I'm still waiting for the example of how you want the output to look. Your workbook doesn't have any vba code in it...you might get more support if it at least appeared you had first attempted coding this yourself as well. Just a suggestion. Thanks!

  7. #7
    Registered User
    Join Date
    08-23-2011
    Location
    East
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Compare cell by cell in sheets

    i had created the COPIED worksheet to copy paste all the items that match with sheet 2....i had tried writing the code but could not find it in my uploaded sheet...i m not sure that my office proxy had deleted it or not.?

  8. #8
    Registered User
    Join Date
    08-23-2011
    Location
    East
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Compare cell by cell in sheets

    hello sirs,,,kindly tell me how can i complete this query..

  9. #9
    Registered User
    Join Date
    08-23-2011
    Location
    East
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Compare cell by cell in sheets

    more than 3days no solution.hope it is not that much impossible..

  10. #10
    Registered User
    Join Date
    08-23-2011
    Location
    East
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Compare cell by cell in sheets

    Thanks ,,gjlindn for that great reply.sorry i forgot to upload the example...will upload the example with in few minutes...

  11. #11
    Registered User
    Join Date
    08-23-2011
    Location
    East
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Compare cell by cell in sheets

    hmmm.after a great struggle and searching from many codes & examples in vba.i could make out my problem but could not finish it.not sure,i m bowled out in the last lines of code...

    i m very new to coding & all the credits to the original coders from where i had copied the code..


    attached the updated version of example with vba code.....
    Attached Files Attached Files

  12. #12
    Valued Forum Contributor
    Join Date
    11-11-2008
    Location
    Euro
    MS-Off Ver
    2007, 2010
    Posts
    470

    Re: Compare cell by cell in sheets

    There is no any code-line in your attached file?

    In the result sheets (copies), why there exists "south american" in cell A4 that is not match any record in Src sheet?

    how many records is there in your database?
    and The records in the column A in Sheet Mast are unique?
    Best regard, -)iger-/iger
    If you are pleased with a solution mark your post SOLVED.

  13. #13
    Registered User
    Join Date
    08-23-2011
    Location
    East
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Compare cell by cell in sheets

    Sorry dude,,i had attached the example with code.but again its getting deleted..i could not find the reason....

  14. #14
    Registered User
    Join Date
    08-23-2011
    Location
    East
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Compare cell by cell in sheets

    mr.tiger there is no such word like"southamerican"as quoted by you in my example sheet.

    to the number of records question:my worksheet contains not less than 4000 lines everyday.

  15. #15
    Registered User
    Join Date
    08-23-2011
    Location
    East
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Compare cell by cell in sheets

    Here is the sample code i had copied and tried adjusting to my requirements.pls tell me what more to be added.
    Private Sub comparcells()
        Dim fRow As Long
        
        Dim rng1 As Range
        Dim rng2 As Range
        
        Dim cel As Range
        Dim fOne As String
        Dim fTwo As String
        
        Dim ws1 As Worksheet
        Dim ws2 As Worksheet
         
        Set ws1 = Sheets("Src")
        Set ws2 = Sheets("mast")
         
          Worksheets.Add
                ActiveSheet.Name = "copies"
         
        With ws1
              Set rng1 = Range(.Cells(1, 1), .Cells(65536, 1).End(xlUp))
          
        End With
         
         
        With ws2
           'row 1 to last row of data Sheet src:ColA
            Set rng2 = Range(.Cells(1, 1), .Cells(65536, 1).End(xlUp))
            For Each cel In rng1
                         
                fOne = cel
                         
                fTwo = cel
                
                 On Error Resume Next
                 
                 'Find Sheet src:ColA in Sheet 2
                fRow = .Cells.Find(What:=fOne, After:=Range("A1"), LookIn:=xlFormulas, LookAt:= _
                xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
                , SearchFormat:=False).row
    
    If fOne = fTwo Then
     ActiveCell.EntireRow.Copy("copies").Paste
     End If
     Next cel
     End With
     
    End Sub

  16. #16
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Compare cell by cell in sheets

    Here you go!
    Option Explicit
    Option Compare Text
    
    Sub CompareValues()
        Dim wsCopies    As Worksheet
        Dim rFirst      As Range
        Dim rSecond     As Range
        Dim rCell       As Range
        Dim rMatch      As Range
        Dim lCount      As Long
        Dim bScrUpd     As Boolean
        Dim bEvents     As Boolean
        Dim lCalc       As Long
        
        'Improve performance
        With Application
            bScrUpd = .ScreenUpdating
            bEvents = .EnableEvents
            lCalc = .Calculation
            .ScreenUpdating = False
            .EnableEvents = False
            .Calculation = xlCalculationManual
        End With
        
        'Change A1:A19 to your range with duplicate values
        Set rFirst = Sheets("src").Range("A1:A19")
        
        'Change A1:A6 to your range with no duplicate values
        Set rSecond = Sheets("Mast").Range("A1:A6")
        
        'Set worksheet Copies = worksheet object wsCopies
        On Error Resume Next
            Set wsCopies = Sheets("Copies")
            wsCopies.Cells.Clear
            If Err.Number <> 0 Then
                Set wsCopies = Worksheets.Add(After:=Sheets(Sheets.Count))
                wsCopies.Name = "Copies"
            End If
        On Error GoTo 0
        
        'Find rSecond in rFirst and add to Copies worksheet
        For Each rCell In rSecond
            Set rMatch = rFirst.Find(rSecond, LookIn:=xlValues, LookAt:=xlWhole)
            If Not rMatch Is Nothing Then
                Set rCell = rCell.Resize(1, 2)
                wsCopies.Cells(lCount + 1, 1).Resize(1, _
                    rCell.Columns.Count).Value = rCell.Value
                lCount = lCount + 1
            End If
        Next
        
        'Clean up
        Set rFirst = Nothing
        Set rSecond = Nothing
        Set rMatch = Nothing
        Set rCell = Nothing
        
        'Restore Application settings
        With Application
            .ScreenUpdating = bScrUpd
            .EnableEvents = bEvents
            .Calculation = lCalc
        End With
    End Sub
    Good luck!
    Last edited by gjlindn; 09-02-2011 at 01:29 AM. Reason: Corrected boolean to Long

  17. #17
    Registered User
    Join Date
    08-23-2011
    Location
    East
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: Compare cell by cell in sheets

    Thanks mate..that was a rocking one..

  18. #18
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Compare cell by cell in sheets

    You're welcome If that's working for you, would you mind marking this thread as SOLVED? Also, if you wouldn't mind, it would help me out if you'd click the scales to the right of my post. Thanks and have a great day!

  19. #19
    Valued Forum Contributor
    Join Date
    11-11-2008
    Location
    Euro
    MS-Off Ver
    2007, 2010
    Posts
    470

    Re: Compare cell by cell in sheets

    Try to a new approach,

    see the attached file, and Plz confirms the code is appropriate for your case or not
    Attached Files Attached Files
    Last edited by tigertiger; 09-03-2011 at 08:27 AM.

+ 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