how to compare two column and copy the value in VBA Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How do I copy a file in Python?How to clone or copy a list?How to copy a folder from remote to local using scp?With VBA, how to sort data with different conditions?Compare two data sets in different sheet and print difference in other sheet using excel VBA?Excel VBA look for values in other sheet and copy themVBA - compare the cells in two columns with the cells in two other columnsCopy Range Sheet1 Paste in Active Cell Sheet 2Partial matching between two columns and copy corresponding cell VBAVBA Code to Check one Column Data with Multiple Columns Data?

How to write the following sign?

What is the font for "b" letter?

Why is my ESD wriststrap failing with nitrile gloves on?

Sum letters are not two different

Is grep documentation about ignoring case wrong, since it doesn't ignore case in filenames?

Significance of Cersei's obsession with elephants?

Why aren't air breathing engines used as small first stages?

Localisation of Category

How would a mousetrap for use in space work?

How does the math work when buying airline miles?

Trademark violation for app?

Generate an RGB colour grid

Why do we bend a book to keep it straight?

Find 108 by using 3,4,6

Crossing US/Canada Border for less than 24 hours

How to react to hostile behavior from a senior developer?

Chinese Seal on silk painting - what does it mean?

Why is it faster to reheat something than it is to cook it?

What do you call the main part of a joke?

Selecting user stories during sprint planning

Maximum summed subsequences with non-adjacent items

Did Krishna say in Bhagavad Gita "I am in every living being"

What does it mean that physics no longer uses mechanical models to describe phenomena?

SF book about people trapped in a series of worlds they imagine



how to compare two column and copy the value in VBA



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How do I copy a file in Python?How to clone or copy a list?How to copy a folder from remote to local using scp?With VBA, how to sort data with different conditions?Compare two data sets in different sheet and print difference in other sheet using excel VBA?Excel VBA look for values in other sheet and copy themVBA - compare the cells in two columns with the cells in two other columnsCopy Range Sheet1 Paste in Active Cell Sheet 2Partial matching between two columns and copy corresponding cell VBAVBA Code to Check one Column Data with Multiple Columns Data?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm trying to figure out how to write compare code. I have two sheets', sheet1 and sheet2.



in sheet1 have five digits id numbers in column A, in sheet2 have same five digits id number in column C, but in sheet2 the id number is not the same row as column A in sheet1, they are differents row.



I'm trying to figure out how to make comparisons in sheet1 column A to search for a match in ANY row in sheet2 column B then copy the value from the same row in sheet2 Column C to sheet1 column D!



this is my own testing code but is not working.



Sub FindStuff()

Dim lr As Long
Dim i As Integer

lr = Sheet1.Range("A" & Rows.Count).End(xlUp).Row

For i = 1 To lr

If UCase(Sheet2.Cells(1, 3).Value) = UCase(Sheet1.Cells(i, 1).Value) Then
Sheet2.Cells(14, 5).Value = Sheet1.Cells(i, 1).Offset(, 5).Value
End If
Next i

End Sub









share|improve this question






























    0















    I'm trying to figure out how to write compare code. I have two sheets', sheet1 and sheet2.



    in sheet1 have five digits id numbers in column A, in sheet2 have same five digits id number in column C, but in sheet2 the id number is not the same row as column A in sheet1, they are differents row.



    I'm trying to figure out how to make comparisons in sheet1 column A to search for a match in ANY row in sheet2 column B then copy the value from the same row in sheet2 Column C to sheet1 column D!



    this is my own testing code but is not working.



    Sub FindStuff()

    Dim lr As Long
    Dim i As Integer

    lr = Sheet1.Range("A" & Rows.Count).End(xlUp).Row

    For i = 1 To lr

    If UCase(Sheet2.Cells(1, 3).Value) = UCase(Sheet1.Cells(i, 1).Value) Then
    Sheet2.Cells(14, 5).Value = Sheet1.Cells(i, 1).Offset(, 5).Value
    End If
    Next i

    End Sub









    share|improve this question


























      0












      0








      0








      I'm trying to figure out how to write compare code. I have two sheets', sheet1 and sheet2.



      in sheet1 have five digits id numbers in column A, in sheet2 have same five digits id number in column C, but in sheet2 the id number is not the same row as column A in sheet1, they are differents row.



      I'm trying to figure out how to make comparisons in sheet1 column A to search for a match in ANY row in sheet2 column B then copy the value from the same row in sheet2 Column C to sheet1 column D!



      this is my own testing code but is not working.



      Sub FindStuff()

      Dim lr As Long
      Dim i As Integer

      lr = Sheet1.Range("A" & Rows.Count).End(xlUp).Row

      For i = 1 To lr

      If UCase(Sheet2.Cells(1, 3).Value) = UCase(Sheet1.Cells(i, 1).Value) Then
      Sheet2.Cells(14, 5).Value = Sheet1.Cells(i, 1).Offset(, 5).Value
      End If
      Next i

      End Sub









      share|improve this question
















      I'm trying to figure out how to write compare code. I have two sheets', sheet1 and sheet2.



      in sheet1 have five digits id numbers in column A, in sheet2 have same five digits id number in column C, but in sheet2 the id number is not the same row as column A in sheet1, they are differents row.



      I'm trying to figure out how to make comparisons in sheet1 column A to search for a match in ANY row in sheet2 column B then copy the value from the same row in sheet2 Column C to sheet1 column D!



      this is my own testing code but is not working.



      Sub FindStuff()

      Dim lr As Long
      Dim i As Integer

      lr = Sheet1.Range("A" & Rows.Count).End(xlUp).Row

      For i = 1 To lr

      If UCase(Sheet2.Cells(1, 3).Value) = UCase(Sheet1.Cells(i, 1).Value) Then
      Sheet2.Cells(14, 5).Value = Sheet1.Cells(i, 1).Offset(, 5).Value
      End If
      Next i

      End Sub






      excel vba copy paste






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 23:17







      Andy

















      asked Mar 8 at 20:15









      Andy Andy

      52




      52






















          1 Answer
          1






          active

          oldest

          votes


















          -1














          The code you post has both syntax error and logic error, I'm not sure exactly what you are trying to do. Can you post an workbook example?
          I changed your formula with Vlookup in the code, you can test and let me know if this is what you need.



          Sub MatchValues()
          Dim ws1 As Worksheet, ws2 As Worksheet
          Dim lr As Long
          Dim r As Long

          Application.ScreenUpdating = False
          Set ws1 = Sheets("Sheet1")
          Set ws2 = Sheets("Sheet2")
          lr = ws2.Cells(Rows.Count, 3).End(xlUp).Row

          For r = 2 To lr
          On Error Resume Next
          Cells(r, 4) = WorksheetFunction.VLookup(ws2.Cells(r, 3).Value, _
          ws1.Range("A:A"), 1, 0)
          Next

          Application.ScreenUpdating = True
          End Sub





          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070410%2fhow-to-compare-two-column-and-copy-the-value-in-vba%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            -1














            The code you post has both syntax error and logic error, I'm not sure exactly what you are trying to do. Can you post an workbook example?
            I changed your formula with Vlookup in the code, you can test and let me know if this is what you need.



            Sub MatchValues()
            Dim ws1 As Worksheet, ws2 As Worksheet
            Dim lr As Long
            Dim r As Long

            Application.ScreenUpdating = False
            Set ws1 = Sheets("Sheet1")
            Set ws2 = Sheets("Sheet2")
            lr = ws2.Cells(Rows.Count, 3).End(xlUp).Row

            For r = 2 To lr
            On Error Resume Next
            Cells(r, 4) = WorksheetFunction.VLookup(ws2.Cells(r, 3).Value, _
            ws1.Range("A:A"), 1, 0)
            Next

            Application.ScreenUpdating = True
            End Sub





            share|improve this answer





























              -1














              The code you post has both syntax error and logic error, I'm not sure exactly what you are trying to do. Can you post an workbook example?
              I changed your formula with Vlookup in the code, you can test and let me know if this is what you need.



              Sub MatchValues()
              Dim ws1 As Worksheet, ws2 As Worksheet
              Dim lr As Long
              Dim r As Long

              Application.ScreenUpdating = False
              Set ws1 = Sheets("Sheet1")
              Set ws2 = Sheets("Sheet2")
              lr = ws2.Cells(Rows.Count, 3).End(xlUp).Row

              For r = 2 To lr
              On Error Resume Next
              Cells(r, 4) = WorksheetFunction.VLookup(ws2.Cells(r, 3).Value, _
              ws1.Range("A:A"), 1, 0)
              Next

              Application.ScreenUpdating = True
              End Sub





              share|improve this answer



























                -1












                -1








                -1







                The code you post has both syntax error and logic error, I'm not sure exactly what you are trying to do. Can you post an workbook example?
                I changed your formula with Vlookup in the code, you can test and let me know if this is what you need.



                Sub MatchValues()
                Dim ws1 As Worksheet, ws2 As Worksheet
                Dim lr As Long
                Dim r As Long

                Application.ScreenUpdating = False
                Set ws1 = Sheets("Sheet1")
                Set ws2 = Sheets("Sheet2")
                lr = ws2.Cells(Rows.Count, 3).End(xlUp).Row

                For r = 2 To lr
                On Error Resume Next
                Cells(r, 4) = WorksheetFunction.VLookup(ws2.Cells(r, 3).Value, _
                ws1.Range("A:A"), 1, 0)
                Next

                Application.ScreenUpdating = True
                End Sub





                share|improve this answer















                The code you post has both syntax error and logic error, I'm not sure exactly what you are trying to do. Can you post an workbook example?
                I changed your formula with Vlookup in the code, you can test and let me know if this is what you need.



                Sub MatchValues()
                Dim ws1 As Worksheet, ws2 As Worksheet
                Dim lr As Long
                Dim r As Long

                Application.ScreenUpdating = False
                Set ws1 = Sheets("Sheet1")
                Set ws2 = Sheets("Sheet2")
                lr = ws2.Cells(Rows.Count, 3).End(xlUp).Row

                For r = 2 To lr
                On Error Resume Next
                Cells(r, 4) = WorksheetFunction.VLookup(ws2.Cells(r, 3).Value, _
                ws1.Range("A:A"), 1, 0)
                Next

                Application.ScreenUpdating = True
                End Sub






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 8 at 23:47

























                answered Mar 8 at 21:17









                Peicong ChenPeicong Chen

                643




                643





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070410%2fhow-to-compare-two-column-and-copy-the-value-in-vba%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

                    Алба-Юлія

                    Захаров Федір Захарович