VBa Copy error “We cant paste because the copy and paste area are not the same size”









up vote
0
down vote

favorite












Please help me debug this code. I am compiling a report from 100 files. This code works for almost all the files but for some this error pops up. The format for all the files is the same only the row count differs



sh.Range("A2:H" & lastRow).Copy 
Destination:=wb1.Worksheets("MainSheet").Range("A" & mainrow)

A2&last row = A2:H17408
"A" & mainrow=A1033559









share|improve this question























  • The reason is there are max 1048576 rows available on a sheet and there isn't enough room for the data to be pasted.
    – sktneer
    Nov 10 at 7:27










  • How can i extend the max
    – prajwal rao
    Nov 10 at 7:31










  • No, you can't..
    – sktneer
    Nov 10 at 7:33










  • Write to a database, perform aggregations etc there and then pull into Excel.
    – QHarr
    Nov 10 at 9:25











  • other possible solution : when the limit on one sheet is reached, create a new sheet and copy the data to the new sheet
    – h2so4
    Nov 10 at 9:43














up vote
0
down vote

favorite












Please help me debug this code. I am compiling a report from 100 files. This code works for almost all the files but for some this error pops up. The format for all the files is the same only the row count differs



sh.Range("A2:H" & lastRow).Copy 
Destination:=wb1.Worksheets("MainSheet").Range("A" & mainrow)

A2&last row = A2:H17408
"A" & mainrow=A1033559









share|improve this question























  • The reason is there are max 1048576 rows available on a sheet and there isn't enough room for the data to be pasted.
    – sktneer
    Nov 10 at 7:27










  • How can i extend the max
    – prajwal rao
    Nov 10 at 7:31










  • No, you can't..
    – sktneer
    Nov 10 at 7:33










  • Write to a database, perform aggregations etc there and then pull into Excel.
    – QHarr
    Nov 10 at 9:25











  • other possible solution : when the limit on one sheet is reached, create a new sheet and copy the data to the new sheet
    – h2so4
    Nov 10 at 9:43












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Please help me debug this code. I am compiling a report from 100 files. This code works for almost all the files but for some this error pops up. The format for all the files is the same only the row count differs



sh.Range("A2:H" & lastRow).Copy 
Destination:=wb1.Worksheets("MainSheet").Range("A" & mainrow)

A2&last row = A2:H17408
"A" & mainrow=A1033559









share|improve this question















Please help me debug this code. I am compiling a report from 100 files. This code works for almost all the files but for some this error pops up. The format for all the files is the same only the row count differs



sh.Range("A2:H" & lastRow).Copy 
Destination:=wb1.Worksheets("MainSheet").Range("A" & mainrow)

A2&last row = A2:H17408
"A" & mainrow=A1033559






excel vba copy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 10:00









Rajeev Atmakuri

6401719




6401719










asked Nov 10 at 7:24









prajwal rao

1




1











  • The reason is there are max 1048576 rows available on a sheet and there isn't enough room for the data to be pasted.
    – sktneer
    Nov 10 at 7:27










  • How can i extend the max
    – prajwal rao
    Nov 10 at 7:31










  • No, you can't..
    – sktneer
    Nov 10 at 7:33










  • Write to a database, perform aggregations etc there and then pull into Excel.
    – QHarr
    Nov 10 at 9:25











  • other possible solution : when the limit on one sheet is reached, create a new sheet and copy the data to the new sheet
    – h2so4
    Nov 10 at 9:43
















  • The reason is there are max 1048576 rows available on a sheet and there isn't enough room for the data to be pasted.
    – sktneer
    Nov 10 at 7:27










  • How can i extend the max
    – prajwal rao
    Nov 10 at 7:31










  • No, you can't..
    – sktneer
    Nov 10 at 7:33










  • Write to a database, perform aggregations etc there and then pull into Excel.
    – QHarr
    Nov 10 at 9:25











  • other possible solution : when the limit on one sheet is reached, create a new sheet and copy the data to the new sheet
    – h2so4
    Nov 10 at 9:43















The reason is there are max 1048576 rows available on a sheet and there isn't enough room for the data to be pasted.
– sktneer
Nov 10 at 7:27




The reason is there are max 1048576 rows available on a sheet and there isn't enough room for the data to be pasted.
– sktneer
Nov 10 at 7:27












How can i extend the max
– prajwal rao
Nov 10 at 7:31




How can i extend the max
– prajwal rao
Nov 10 at 7:31












No, you can't..
– sktneer
Nov 10 at 7:33




No, you can't..
– sktneer
Nov 10 at 7:33












Write to a database, perform aggregations etc there and then pull into Excel.
– QHarr
Nov 10 at 9:25





Write to a database, perform aggregations etc there and then pull into Excel.
– QHarr
Nov 10 at 9:25













other possible solution : when the limit on one sheet is reached, create a new sheet and copy the data to the new sheet
– h2so4
Nov 10 at 9:43




other possible solution : when the limit on one sheet is reached, create a new sheet and copy the data to the new sheet
– h2so4
Nov 10 at 9:43












2 Answers
2






active

oldest

votes

















up vote
0
down vote













There are multiple reasons to get this error message
1. When you are pasting merged cells to non-merged cells or visa-versa.
2. When you applied a filter to sheet, and tried to paste which is not same size as copied data.






share|improve this answer



























    up vote
    0
    down vote













    your code is too limited to be sure of a 100% correct answer, as we do not see how you have defined your variables.
    However, assuming they are correctly defined, it is better to use this:



    Dim ws as worksheet
    Set ws = wb1.Sheets("MainSheet")

    ' Range goes from columns A to H with mainrow and LastRow as variable rows
    ws.Range(ws.Cells(mainrow, 1), ws.Cells(LastRow, 8)).Value = sh.Range(sh.Cells(mainrow, 1), sh.Cells(LastRow, 8)).Value


    instead of a copy-paste.
    Apart from that, make sure mainrow and LastRow are defined correctly. When in doubt, add this part of your code in an edited question, so we can have a look at it.






    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',
      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%2f53236871%2fvba-copy-error-we-cant-paste-because-the-copy-and-paste-area-are-not-the-same-s%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      There are multiple reasons to get this error message
      1. When you are pasting merged cells to non-merged cells or visa-versa.
      2. When you applied a filter to sheet, and tried to paste which is not same size as copied data.






      share|improve this answer
























        up vote
        0
        down vote













        There are multiple reasons to get this error message
        1. When you are pasting merged cells to non-merged cells or visa-versa.
        2. When you applied a filter to sheet, and tried to paste which is not same size as copied data.






        share|improve this answer






















          up vote
          0
          down vote










          up vote
          0
          down vote









          There are multiple reasons to get this error message
          1. When you are pasting merged cells to non-merged cells or visa-versa.
          2. When you applied a filter to sheet, and tried to paste which is not same size as copied data.






          share|improve this answer












          There are multiple reasons to get this error message
          1. When you are pasting merged cells to non-merged cells or visa-versa.
          2. When you applied a filter to sheet, and tried to paste which is not same size as copied data.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 10 at 10:14









          Arun Banakar

          512




          512






















              up vote
              0
              down vote













              your code is too limited to be sure of a 100% correct answer, as we do not see how you have defined your variables.
              However, assuming they are correctly defined, it is better to use this:



              Dim ws as worksheet
              Set ws = wb1.Sheets("MainSheet")

              ' Range goes from columns A to H with mainrow and LastRow as variable rows
              ws.Range(ws.Cells(mainrow, 1), ws.Cells(LastRow, 8)).Value = sh.Range(sh.Cells(mainrow, 1), sh.Cells(LastRow, 8)).Value


              instead of a copy-paste.
              Apart from that, make sure mainrow and LastRow are defined correctly. When in doubt, add this part of your code in an edited question, so we can have a look at it.






              share|improve this answer
























                up vote
                0
                down vote













                your code is too limited to be sure of a 100% correct answer, as we do not see how you have defined your variables.
                However, assuming they are correctly defined, it is better to use this:



                Dim ws as worksheet
                Set ws = wb1.Sheets("MainSheet")

                ' Range goes from columns A to H with mainrow and LastRow as variable rows
                ws.Range(ws.Cells(mainrow, 1), ws.Cells(LastRow, 8)).Value = sh.Range(sh.Cells(mainrow, 1), sh.Cells(LastRow, 8)).Value


                instead of a copy-paste.
                Apart from that, make sure mainrow and LastRow are defined correctly. When in doubt, add this part of your code in an edited question, so we can have a look at it.






                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  your code is too limited to be sure of a 100% correct answer, as we do not see how you have defined your variables.
                  However, assuming they are correctly defined, it is better to use this:



                  Dim ws as worksheet
                  Set ws = wb1.Sheets("MainSheet")

                  ' Range goes from columns A to H with mainrow and LastRow as variable rows
                  ws.Range(ws.Cells(mainrow, 1), ws.Cells(LastRow, 8)).Value = sh.Range(sh.Cells(mainrow, 1), sh.Cells(LastRow, 8)).Value


                  instead of a copy-paste.
                  Apart from that, make sure mainrow and LastRow are defined correctly. When in doubt, add this part of your code in an edited question, so we can have a look at it.






                  share|improve this answer












                  your code is too limited to be sure of a 100% correct answer, as we do not see how you have defined your variables.
                  However, assuming they are correctly defined, it is better to use this:



                  Dim ws as worksheet
                  Set ws = wb1.Sheets("MainSheet")

                  ' Range goes from columns A to H with mainrow and LastRow as variable rows
                  ws.Range(ws.Cells(mainrow, 1), ws.Cells(LastRow, 8)).Value = sh.Range(sh.Cells(mainrow, 1), sh.Cells(LastRow, 8)).Value


                  instead of a copy-paste.
                  Apart from that, make sure mainrow and LastRow are defined correctly. When in doubt, add this part of your code in an edited question, so we can have a look at it.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 10 at 15:18









                  Lambik

                  31319




                  31319



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236871%2fvba-copy-error-we-cant-paste-because-the-copy-and-paste-area-are-not-the-same-s%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







                      這個網誌中的熱門文章

                      How to read a connectionString WITH PROVIDER in .NET Core?

                      Node.js Script on GitHub Pages or Amazon S3

                      Museum of Modern and Contemporary Art of Trento and Rovereto