Compare multiple columns in two sheets to get a value












0














I have limited working knowledge of Excel VBA macros.
I have two sheets called "Summary" and "Data"




  • The Summary sheet has fixed rows and columns.

  • The Data sheet has values in it.


I need to compare the Code, Company MRC number and Status of the Summary and Data sheets and if the fields match then get the corresponding value from Data sheet to Summary field.



Excel










share|improve this question





























    0














    I have limited working knowledge of Excel VBA macros.
    I have two sheets called "Summary" and "Data"




    • The Summary sheet has fixed rows and columns.

    • The Data sheet has values in it.


    I need to compare the Code, Company MRC number and Status of the Summary and Data sheets and if the fields match then get the corresponding value from Data sheet to Summary field.



    Excel










    share|improve this question



























      0












      0








      0







      I have limited working knowledge of Excel VBA macros.
      I have two sheets called "Summary" and "Data"




      • The Summary sheet has fixed rows and columns.

      • The Data sheet has values in it.


      I need to compare the Code, Company MRC number and Status of the Summary and Data sheets and if the fields match then get the corresponding value from Data sheet to Summary field.



      Excel










      share|improve this question















      I have limited working knowledge of Excel VBA macros.
      I have two sheets called "Summary" and "Data"




      • The Summary sheet has fixed rows and columns.

      • The Data sheet has values in it.


      I need to compare the Code, Company MRC number and Status of the Summary and Data sheets and if the fields match then get the corresponding value from Data sheet to Summary field.



      Excel







      microsoft-excel vba






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 24 '18 at 13:08









      Blackwood

      2,89461728




      2,89461728










      asked Dec 23 '18 at 21:42









      Opc ChewOpc Chew

      1




      1






















          1 Answer
          1






          active

          oldest

          votes


















          0














          My solution is based on the attached Screen Shot, where I found only two common Columns between Sheets, are



          1. Code



          2. Company MRC



          I'm unable to find Status Of Summary & Data field.



          I would like to suggest set of Macros to compare both Sheets for common data to be copied into another Sheet.



          Sub CompareRanges()

          Dim WorkRng1 As Range, WorkRng2 As Range, Rng1 As Range, Rng2 As Range

          Set WorkRng1 = Application.InputBox("Range A:", "", Type:=8)
          Set WorkRng2 = Application.InputBox("Range B:", Type:=8)

          For Each Rng1 In WorkRng1
          rng1Value = Rng1.Value

          For Each Rng2 In WorkRng2

          If rng1Value = Rng2.Value Then
          Rng1.Interior.Color = VBA.RGB(255, 0, 0)
          Exit For

          End If
          Next
          Next

          End Sub


          How it works:




          1. Respond both Input Boxes with an appropriate Data Range from both Sheets to be compared.

          2. Macro will highlight duplicate Data in Sheet 1(Data Sheet) with Red color.


          3. RUN the below written Macro to Copy Duplicate Data.

          4. Copy both Macros as Standard Module.


          Edited:



          Do the following to avoid using the second Macro:




          1. Select the data range in DATA Sheet & apply Auto Filter.


          2. Filter Rows in Red Color.


          3. Copy Filtered Rows.


          4. Place the Cell pointer at required Cell & apply Pastes Special then Click Value.



            Sub CopyRedRows()

            Dim wks As Worksheet
            Dim wNew As Worksheet
            Dim lRow As Long
            Dim lNewRow As Long
            Dim x As Long

            Set wks = Sheets("Data")
            lRow = wks.Cells.SpecialCells(xlCellTypeLastCell).Row

            Set wNew = Sheets("Summary")
            lNewRow = 10

            For x = 1 To lRow
            If wks.Cells(x, 1).Interior.Color = vbRed Then
            wks.Cells(x, 1).EntireRow.Copy wNew.Cells(lNewRow, 1)
            lNewRow = lNewRow + 1
            End If
            Next

            End Sub


          5. Sheet Name, RGB Color Code & lNewRow values are editable.







          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            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%2fsuperuser.com%2fquestions%2f1387223%2fcompare-multiple-columns-in-two-sheets-to-get-a-value%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









            0














            My solution is based on the attached Screen Shot, where I found only two common Columns between Sheets, are



            1. Code



            2. Company MRC



            I'm unable to find Status Of Summary & Data field.



            I would like to suggest set of Macros to compare both Sheets for common data to be copied into another Sheet.



            Sub CompareRanges()

            Dim WorkRng1 As Range, WorkRng2 As Range, Rng1 As Range, Rng2 As Range

            Set WorkRng1 = Application.InputBox("Range A:", "", Type:=8)
            Set WorkRng2 = Application.InputBox("Range B:", Type:=8)

            For Each Rng1 In WorkRng1
            rng1Value = Rng1.Value

            For Each Rng2 In WorkRng2

            If rng1Value = Rng2.Value Then
            Rng1.Interior.Color = VBA.RGB(255, 0, 0)
            Exit For

            End If
            Next
            Next

            End Sub


            How it works:




            1. Respond both Input Boxes with an appropriate Data Range from both Sheets to be compared.

            2. Macro will highlight duplicate Data in Sheet 1(Data Sheet) with Red color.


            3. RUN the below written Macro to Copy Duplicate Data.

            4. Copy both Macros as Standard Module.


            Edited:



            Do the following to avoid using the second Macro:




            1. Select the data range in DATA Sheet & apply Auto Filter.


            2. Filter Rows in Red Color.


            3. Copy Filtered Rows.


            4. Place the Cell pointer at required Cell & apply Pastes Special then Click Value.



              Sub CopyRedRows()

              Dim wks As Worksheet
              Dim wNew As Worksheet
              Dim lRow As Long
              Dim lNewRow As Long
              Dim x As Long

              Set wks = Sheets("Data")
              lRow = wks.Cells.SpecialCells(xlCellTypeLastCell).Row

              Set wNew = Sheets("Summary")
              lNewRow = 10

              For x = 1 To lRow
              If wks.Cells(x, 1).Interior.Color = vbRed Then
              wks.Cells(x, 1).EntireRow.Copy wNew.Cells(lNewRow, 1)
              lNewRow = lNewRow + 1
              End If
              Next

              End Sub


            5. Sheet Name, RGB Color Code & lNewRow values are editable.







            share|improve this answer




























              0














              My solution is based on the attached Screen Shot, where I found only two common Columns between Sheets, are



              1. Code



              2. Company MRC



              I'm unable to find Status Of Summary & Data field.



              I would like to suggest set of Macros to compare both Sheets for common data to be copied into another Sheet.



              Sub CompareRanges()

              Dim WorkRng1 As Range, WorkRng2 As Range, Rng1 As Range, Rng2 As Range

              Set WorkRng1 = Application.InputBox("Range A:", "", Type:=8)
              Set WorkRng2 = Application.InputBox("Range B:", Type:=8)

              For Each Rng1 In WorkRng1
              rng1Value = Rng1.Value

              For Each Rng2 In WorkRng2

              If rng1Value = Rng2.Value Then
              Rng1.Interior.Color = VBA.RGB(255, 0, 0)
              Exit For

              End If
              Next
              Next

              End Sub


              How it works:




              1. Respond both Input Boxes with an appropriate Data Range from both Sheets to be compared.

              2. Macro will highlight duplicate Data in Sheet 1(Data Sheet) with Red color.


              3. RUN the below written Macro to Copy Duplicate Data.

              4. Copy both Macros as Standard Module.


              Edited:



              Do the following to avoid using the second Macro:




              1. Select the data range in DATA Sheet & apply Auto Filter.


              2. Filter Rows in Red Color.


              3. Copy Filtered Rows.


              4. Place the Cell pointer at required Cell & apply Pastes Special then Click Value.



                Sub CopyRedRows()

                Dim wks As Worksheet
                Dim wNew As Worksheet
                Dim lRow As Long
                Dim lNewRow As Long
                Dim x As Long

                Set wks = Sheets("Data")
                lRow = wks.Cells.SpecialCells(xlCellTypeLastCell).Row

                Set wNew = Sheets("Summary")
                lNewRow = 10

                For x = 1 To lRow
                If wks.Cells(x, 1).Interior.Color = vbRed Then
                wks.Cells(x, 1).EntireRow.Copy wNew.Cells(lNewRow, 1)
                lNewRow = lNewRow + 1
                End If
                Next

                End Sub


              5. Sheet Name, RGB Color Code & lNewRow values are editable.







              share|improve this answer


























                0












                0








                0






                My solution is based on the attached Screen Shot, where I found only two common Columns between Sheets, are



                1. Code



                2. Company MRC



                I'm unable to find Status Of Summary & Data field.



                I would like to suggest set of Macros to compare both Sheets for common data to be copied into another Sheet.



                Sub CompareRanges()

                Dim WorkRng1 As Range, WorkRng2 As Range, Rng1 As Range, Rng2 As Range

                Set WorkRng1 = Application.InputBox("Range A:", "", Type:=8)
                Set WorkRng2 = Application.InputBox("Range B:", Type:=8)

                For Each Rng1 In WorkRng1
                rng1Value = Rng1.Value

                For Each Rng2 In WorkRng2

                If rng1Value = Rng2.Value Then
                Rng1.Interior.Color = VBA.RGB(255, 0, 0)
                Exit For

                End If
                Next
                Next

                End Sub


                How it works:




                1. Respond both Input Boxes with an appropriate Data Range from both Sheets to be compared.

                2. Macro will highlight duplicate Data in Sheet 1(Data Sheet) with Red color.


                3. RUN the below written Macro to Copy Duplicate Data.

                4. Copy both Macros as Standard Module.


                Edited:



                Do the following to avoid using the second Macro:




                1. Select the data range in DATA Sheet & apply Auto Filter.


                2. Filter Rows in Red Color.


                3. Copy Filtered Rows.


                4. Place the Cell pointer at required Cell & apply Pastes Special then Click Value.



                  Sub CopyRedRows()

                  Dim wks As Worksheet
                  Dim wNew As Worksheet
                  Dim lRow As Long
                  Dim lNewRow As Long
                  Dim x As Long

                  Set wks = Sheets("Data")
                  lRow = wks.Cells.SpecialCells(xlCellTypeLastCell).Row

                  Set wNew = Sheets("Summary")
                  lNewRow = 10

                  For x = 1 To lRow
                  If wks.Cells(x, 1).Interior.Color = vbRed Then
                  wks.Cells(x, 1).EntireRow.Copy wNew.Cells(lNewRow, 1)
                  lNewRow = lNewRow + 1
                  End If
                  Next

                  End Sub


                5. Sheet Name, RGB Color Code & lNewRow values are editable.







                share|improve this answer














                My solution is based on the attached Screen Shot, where I found only two common Columns between Sheets, are



                1. Code



                2. Company MRC



                I'm unable to find Status Of Summary & Data field.



                I would like to suggest set of Macros to compare both Sheets for common data to be copied into another Sheet.



                Sub CompareRanges()

                Dim WorkRng1 As Range, WorkRng2 As Range, Rng1 As Range, Rng2 As Range

                Set WorkRng1 = Application.InputBox("Range A:", "", Type:=8)
                Set WorkRng2 = Application.InputBox("Range B:", Type:=8)

                For Each Rng1 In WorkRng1
                rng1Value = Rng1.Value

                For Each Rng2 In WorkRng2

                If rng1Value = Rng2.Value Then
                Rng1.Interior.Color = VBA.RGB(255, 0, 0)
                Exit For

                End If
                Next
                Next

                End Sub


                How it works:




                1. Respond both Input Boxes with an appropriate Data Range from both Sheets to be compared.

                2. Macro will highlight duplicate Data in Sheet 1(Data Sheet) with Red color.


                3. RUN the below written Macro to Copy Duplicate Data.

                4. Copy both Macros as Standard Module.


                Edited:



                Do the following to avoid using the second Macro:




                1. Select the data range in DATA Sheet & apply Auto Filter.


                2. Filter Rows in Red Color.


                3. Copy Filtered Rows.


                4. Place the Cell pointer at required Cell & apply Pastes Special then Click Value.



                  Sub CopyRedRows()

                  Dim wks As Worksheet
                  Dim wNew As Worksheet
                  Dim lRow As Long
                  Dim lNewRow As Long
                  Dim x As Long

                  Set wks = Sheets("Data")
                  lRow = wks.Cells.SpecialCells(xlCellTypeLastCell).Row

                  Set wNew = Sheets("Summary")
                  lNewRow = 10

                  For x = 1 To lRow
                  If wks.Cells(x, 1).Interior.Color = vbRed Then
                  wks.Cells(x, 1).EntireRow.Copy wNew.Cells(lNewRow, 1)
                  lNewRow = lNewRow + 1
                  End If
                  Next

                  End Sub


                5. Sheet Name, RGB Color Code & lNewRow values are editable.








                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 25 '18 at 6:28

























                answered Dec 24 '18 at 12:04









                Rajesh SRajesh S

                1




                1






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • 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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2fsuperuser.com%2fquestions%2f1387223%2fcompare-multiple-columns-in-two-sheets-to-get-a-value%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

                    flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                    Mangá

                     ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕