Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP Runtime error 1004 Paste Area Issues

Status
Not open for further replies.

9806102

Programmer
Aug 21, 2009
6
US
Hello Experts,

I am having a issue with a Excel Macro that is going back and forth between sheets and copy and pasting columns using the find function. I am runnign into this runtime error 1004 - somthing about the paste area not being the same? Below is my code:

Dim paste_cell As String
Dim copy_cell As String
pv_ModeNotFound = False

Sheets(Sheet).Select
Cells.Find(Award_Col_Heading, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
copy_cell = Cells(ActiveCell.Row + 1, ActiveCell.Column).Select
If ActiveCell <> "" Then
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("SOE Macro Output").Select
Cells.Find(SOE_Col_Heading, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).Activate
pv_last_row = Cells(60000, ActiveCell.Column).End(xlUp).Row
paste_cell = Cells(pv_last_row + 1, ActiveCell.Column).Select
'Selection.PasteSpecial paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=
'False, Transpose:=False
ActiveSheet.paste
Else
pv_ModeNotFound = True
End If

End Sub

and it is erroring out at the line ActiveSheet.paste. What I believe is happening is that it is losing what it copied but not sure how to fix it. Have been looking at the computer screen for what seems like hours. Any help would be wonderful.

Thank you!
Amanda Mae
 
Guess that you need cells in copy_cell and paste_cell. If so, use 'Set' in front of their definitions.
Avoid selecting, activating and working with ActiveCell or ActiveSheet, most can be done faster and shorter with direct referencing. Moreover, it's hard to track such code.

combo
 
The reason why I do not have cells in copy cells and paste cells is because I am having it paste data and then find the first cell that has no data in it and then paste another set of data below that. It does that five or so times for every "mode". That way it does not paste over the data that it already pasted. Combo, do you understand what i am saying?

Thank you!
 



Are you pasting DATA or FORMULA?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I am pasting the data that I selected from all the mode sheets by column using the find function to find the column headings on both sheets.
 
Can a part of the pasted range be potentially allocated outside the worksheet?

combo
 
it is a posibility that the pasted range could be allocated outside the worksheet. Would I just have it copy and paste all the data to a different sheet and then in the end copy it all over to the sheet where the data is suposta be held?

Not quite sure I understand.

Thank you!
 
It's not possible to paste outside available range:
Code:
Range("IA1:IU1").Copy
Range("A2").Select
ActiveSheet.Paste 'works
Range("II3").Select
ActiveSheet.Paste 'fails
You need to test potential number of last row pasted.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top