Pasting to single cell but still getting "not same size" error.

9tanstaafl9

Well-known Member
Joined
Mar 23, 2008
Messages
535
Hey, sorry to bother you for something that's probably obvious, but it's so obvious I can't seem to find the answer by searching...

I am trying to copy a range form one worksheet and paste it into another. Most of the time it works, but every once in a while I get a 1004 error saying that the areas are not the same size and shape so I can't paste.

I can't figure out why, since I am pasting the range to a only the top left cell, and I thought that was always ok. What's up?

Sheets("Phases").Range("B2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy Destination:=Sheets("summary").Range("A4")

And, yes I know there are too many selects in the above code, but I don't know how to fix it...

Thanks again for any suggestions! I'd understand if it never worked, but when it usually works, it doesn't make sense.

Thanks!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
edited(didn't notice the xlright so I erased my VBA code.):

Try inserting a break on
Selection.Copy Destination:=Sheets("summary").Range("A4") and check the higlighted cells if it will fit the destination. check total number of columns and rows of the selected cells.
 
Last edited:
Upvote 0
GETTING THERE!

Your question made me think of something. When it doesn't work, the range I'm trying to select would be blank, so it would select the entire worksheet, which would cause problems of it's own. Duh! I am an idiot. Will try to fix that now. I added a check for that by inserting:

If Sheets("Phases").Range("B2") = "" Then GoTo BadJob

after my refreshall, and then it goes to the end and pops up a message box telling them that's a bad job.

It kinda works. I'm not getting any errors now, but my badjob catch only works on the 2nd time I run the macro, not the first. It appears that the refresh is happening after I get to this part of the code, even though I did a refreshall earlier in the macro. Is there a way to get it to wait until the refresh is done before going on in the macro? I tried using application.wait and it didn't do the trick (it waited, but paused the refresh too). Help????????????????


Thanks for the advice. I forgot to mention before that I'm a total idiot, at this anyway, generally I'm very smart. How exactly does one insert a break???


THANKYOU!!!!!!!!!!!!!!!!!!

edited(didn't notice the xlright so I erased my VBA code.):

Try inserting a break on
Selection.Copy Destination:=Sheets("summary").Range("A4") and check the higlighted cells if it will fit the destination. check total number of columns and rows of the selected cells.
 
Upvote 0
to insert break in VBA, click the line and press F9 button. You will see a red dot appearing on the left side.


Are you using an embeded object to refresh a data? I encountered this on one of the installed add-ins I have. The solution I did was to find if the embeded object has a default Sub like the one below. This ensures that VBA codes will only run after completion.

i.e.
Private Sub EmbeddedObject1_RequestComplete()
'insert codes after refresh
End Sub
 
Upvote 0
Thankyou Aca. ( iPhone won't let me reply with quote...)

I don't quite follow what you said. For something to be embedded would I have he to embed it or does it happen by itself? Using Microsoft qwery and visual foxpro driver. Pulling data to a worksheet using arrays to consolidate data onto other sheets in the workbooks.

All I want is for my macro to run automatically whenever someone changes either cell a1 or b1 (these cells (date and job number) determine what info the qweries will return. I just need the code to wait for the refresh to finish.

Could you point me to info about or tell me how (exactly, remember I'm a newbie) I could embed something myself to do what you suggested. Thank you!
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,028
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top