How do I implement the VBA module to copy filtered data












0















I need to implement a VBA Macro that copies data from one excel worksheet and puts certain column into another one.



Sub sbCopyRangeToAnotherSheet()

'Method 1
Sheets("Sheet1").Range("A1:B10").Copy Destination:=Sheets("Sheet2").Range("E1")

'Method 2
'Copy the data
Sheets("Sheet1").Range("A1:B10").Copy
'Activate the destination worksheet
Sheets("Sheet2").Activate
'Select the target range
Range("E1").Select
'Paste in the target destination
ActiveSheet.Paste

Application.CutCopyMode = False

End Sub


This wont work for new sheets named for example Sheet 3 neither will it run effectively for filtered data. I need a code that can copy the filtered data and paste certain column into another worksheet.










share|improve this question



























    0















    I need to implement a VBA Macro that copies data from one excel worksheet and puts certain column into another one.



    Sub sbCopyRangeToAnotherSheet()

    'Method 1
    Sheets("Sheet1").Range("A1:B10").Copy Destination:=Sheets("Sheet2").Range("E1")

    'Method 2
    'Copy the data
    Sheets("Sheet1").Range("A1:B10").Copy
    'Activate the destination worksheet
    Sheets("Sheet2").Activate
    'Select the target range
    Range("E1").Select
    'Paste in the target destination
    ActiveSheet.Paste

    Application.CutCopyMode = False

    End Sub


    This wont work for new sheets named for example Sheet 3 neither will it run effectively for filtered data. I need a code that can copy the filtered data and paste certain column into another worksheet.










    share|improve this question

























      0












      0








      0








      I need to implement a VBA Macro that copies data from one excel worksheet and puts certain column into another one.



      Sub sbCopyRangeToAnotherSheet()

      'Method 1
      Sheets("Sheet1").Range("A1:B10").Copy Destination:=Sheets("Sheet2").Range("E1")

      'Method 2
      'Copy the data
      Sheets("Sheet1").Range("A1:B10").Copy
      'Activate the destination worksheet
      Sheets("Sheet2").Activate
      'Select the target range
      Range("E1").Select
      'Paste in the target destination
      ActiveSheet.Paste

      Application.CutCopyMode = False

      End Sub


      This wont work for new sheets named for example Sheet 3 neither will it run effectively for filtered data. I need a code that can copy the filtered data and paste certain column into another worksheet.










      share|improve this question














      I need to implement a VBA Macro that copies data from one excel worksheet and puts certain column into another one.



      Sub sbCopyRangeToAnotherSheet()

      'Method 1
      Sheets("Sheet1").Range("A1:B10").Copy Destination:=Sheets("Sheet2").Range("E1")

      'Method 2
      'Copy the data
      Sheets("Sheet1").Range("A1:B10").Copy
      'Activate the destination worksheet
      Sheets("Sheet2").Activate
      'Select the target range
      Range("E1").Select
      'Paste in the target destination
      ActiveSheet.Paste

      Application.CutCopyMode = False

      End Sub


      This wont work for new sheets named for example Sheet 3 neither will it run effectively for filtered data. I need a code that can copy the filtered data and paste certain column into another worksheet.







      microsoft-excel microsoft-excel-2010 worksheet-function microsoft-excel-2007 vba






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '15 at 6:47









      helloworldhelloworld

      112




      112






















          1 Answer
          1






          active

          oldest

          votes


















          0














          In order to just copy visible cells in a filtered range, you need to specify that that is what you try to do. For instance:



          Sheets("Sheet1").Range("A1:B10").SpecialCells(xlCellTypeVisible).Copy _
          Destination:=Sheets("Sheet2").Range("E1")


          Some good examples of how to use autofilter in VBA-code can, among other places, be found here.



          I can see no reason why this shouldn't work when you refer to other sheets, except for your use of Activate and Select maybe cancelling the copy-action at some point. Any reason you do it that way instead of how I outline it above, with a specified target range specified when you do the copying? I see it's how you do it in your first example, which I assume work.






          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%2f1000759%2fhow-do-i-implement-the-vba-module-to-copy-filtered-data%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














            In order to just copy visible cells in a filtered range, you need to specify that that is what you try to do. For instance:



            Sheets("Sheet1").Range("A1:B10").SpecialCells(xlCellTypeVisible).Copy _
            Destination:=Sheets("Sheet2").Range("E1")


            Some good examples of how to use autofilter in VBA-code can, among other places, be found here.



            I can see no reason why this shouldn't work when you refer to other sheets, except for your use of Activate and Select maybe cancelling the copy-action at some point. Any reason you do it that way instead of how I outline it above, with a specified target range specified when you do the copying? I see it's how you do it in your first example, which I assume work.






            share|improve this answer




























              0














              In order to just copy visible cells in a filtered range, you need to specify that that is what you try to do. For instance:



              Sheets("Sheet1").Range("A1:B10").SpecialCells(xlCellTypeVisible).Copy _
              Destination:=Sheets("Sheet2").Range("E1")


              Some good examples of how to use autofilter in VBA-code can, among other places, be found here.



              I can see no reason why this shouldn't work when you refer to other sheets, except for your use of Activate and Select maybe cancelling the copy-action at some point. Any reason you do it that way instead of how I outline it above, with a specified target range specified when you do the copying? I see it's how you do it in your first example, which I assume work.






              share|improve this answer


























                0












                0








                0







                In order to just copy visible cells in a filtered range, you need to specify that that is what you try to do. For instance:



                Sheets("Sheet1").Range("A1:B10").SpecialCells(xlCellTypeVisible).Copy _
                Destination:=Sheets("Sheet2").Range("E1")


                Some good examples of how to use autofilter in VBA-code can, among other places, be found here.



                I can see no reason why this shouldn't work when you refer to other sheets, except for your use of Activate and Select maybe cancelling the copy-action at some point. Any reason you do it that way instead of how I outline it above, with a specified target range specified when you do the copying? I see it's how you do it in your first example, which I assume work.






                share|improve this answer













                In order to just copy visible cells in a filtered range, you need to specify that that is what you try to do. For instance:



                Sheets("Sheet1").Range("A1:B10").SpecialCells(xlCellTypeVisible).Copy _
                Destination:=Sheets("Sheet2").Range("E1")


                Some good examples of how to use autofilter in VBA-code can, among other places, be found here.



                I can see no reason why this shouldn't work when you refer to other sheets, except for your use of Activate and Select maybe cancelling the copy-action at some point. Any reason you do it that way instead of how I outline it above, with a specified target range specified when you do the copying? I see it's how you do it in your first example, which I assume work.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 16 '15 at 6:58









                eirikdaudeeirikdaude

                6172620




                6172620






























                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1000759%2fhow-do-i-implement-the-vba-module-to-copy-filtered-data%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

                    "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                    Alcedinidae

                    Origin of the phrase “under your belt”?