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
excel vba copy
add a comment |
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
excel vba copy
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
add a comment |
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
excel vba copy
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
excel vba copy
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 10 at 10:14
Arun Banakar
512
512
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 10 at 15:18
Lambik
31319
31319
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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