Solved

Application defined error

Posted on 2011-03-16
9
200 Views
Last Modified: 2012-05-11
Hi,

I have the below code and it errors on

 ActiveSheet.Paste


Application or object defined error.

Can anyone see why this is?

Thanks
Seamus
Windows("balances.xls").Activate
    Columns("A:I").Select
    Selection.Copy
    Windows("Triple_Merit_Template.xls").Activate
    Columns("A:A").Select
    ActiveSheet.Paste
    Range("A2").Select

Open in new window

0
Comment
Question by:Seamus2626
  • 6
  • 3
9 Comments
 
LVL 7

Expert Comment

by:hippohood
ID: 35150191
You can't paste to a sheet, in general. ¿ou should do something like
ActiveCell.Paste

Open in new window

0
 

Author Comment

by:Seamus2626
ID: 35150247
Thanks hippohood, i get the same error though......
0
 
LVL 7

Expert Comment

by:hippohood
ID: 35150255
I am sorry, I am wrong. Yes, you can use the ActiveSheet.Paste.
The problem is somewhere else, let run check your code and see
0
 

Author Comment

by:Seamus2626
ID: 35150294
This is my entire sub

Cheers,
Seamus
Sub Fiscal_Merit_Bals()
'
' Fiscal_Merit_Bals Macro
' Macro recorded 09/03/2011 by Kellum
'

'
Dim r As Long

        
    Workbooks.Open Filename:= _
        "G:\Asset Services MI\UnMatched Merit\Triple_Merit_Template.xls"
    Workbooks.Open Filename:="G:\Asset Services MI\UnMatched Merit\Balances.xls"
    
    Windows("Triple_Merit_Template.xls").Activate
    Rows("1:1").Select
    Selection.AutoFilter
    
    
    
    Windows("balances.xls").Activate
    Columns("A:I").Select
    Selection.Copy
    Windows("Triple_Merit_Template.xls").Activate
    Range("A2").Select
    ActiveCell.Paste
    Range("A2").Select
 
    Windows("Balances.xls").Activate
    ActiveWindow.Close
    Range("A2").Select
    
       
End Sub

Open in new window

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 7

Expert Comment

by:hippohood
ID: 35150328
The issue could be one of the followin:
- the mentioned files are not be open when you run the macro
- the mentioned files are open in different INSTANCES of Excel. Try to close both the files, and then open Excel, and open the fioles using File/Open
- there is anothe rprocess, which interrupts macro action
0
 
LVL 7

Expert Comment

by:hippohood
ID: 35150374
In the shown example Line 25 is wrong - you are trying to insert several columns in a cell atrting A2.
You should either define a rectangular area instead of columns (i.e., "A1:I200" instead of "A:I") or incert into cell in the first row (i.e., A1)
0
 
LVL 7

Accepted Solution

by:
hippohood earned 500 total points
ID: 35150481
I could not generate same error with your macro. But it I know it is not unusual to happen, when you are using Copy/Paste with activating Windows. The problem occur because windows don't get activated, turn out to be minimized, editing is in process, active sheet turn out to be a chart, active cell is in a wroing place or a drawing object is active instead of a cell on the target sheet.

Try replacing lines 21-31 with the ones below. Direct references are usually more reliable
Workbooks("balances.xls").Worksheets(1).Range("A1:I250").Copy
    Workbooks("Triple_Merit_Template.xls").Activate
    Workbooks("Triple_Merit_Template.xls").Worksheets(1).Range("A1").Select
    Workbooks("Triple_Merit_Template.xls").Worksheets(1).Paste
    
    Workbooks("Balances.xls").Close

Open in new window

0
 

Author Closing Comment

by:Seamus2626
ID: 35150703
Found it! Some hidden code in Sheet1

Thanks!
0
 
LVL 7

Expert Comment

by:hippohood
ID: 35151773
So, it was an event handler?
Thank you for the points
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now