LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Error 1004, Application-definded or object-defined error

Hi,

I get an error 1004 in every run but the first in this function in Excel
2002:

---
Public Function CopyWorksheetContent(strSrcWorksheetName As String,
strDestWorksheetName As String) As Boolean
Dim strSheetName As String
Dim lngLastRow As Long

Worksheets(strSrcWorksheetName).Range("A1:J52").Co py

If Not WorksheetNameExists(strDestWorksheetName) Then
strSheetName = AddSheetAtEnd(strDestWorksheetName)
End If

lngLastRow = FindLastRow(strDestWorksheetName, 2)

If lngLastRow 2 Then
lngLastRow = lngLastRow + 1
End If

Worksheets(strDestWorksheetame).Range(Cells(lngLas tRow, 1), Cells
(lngLastRow + 52, 10)).PasteSpecial xlPasteAll
Worksheets(strDestWorksheetName).Range(Cells(lngLa stRow, 1), Cells
(lngLastRow + 52, 10)).AutoFormat Format:=xlRangeAutoFormatSimple,
Number:=False, Font:=False, Alignment:=False, Border:=False, Pattern:=False,
Width:=True

Worksheets(strDestWorksheetName).Cells(lngLastRow, 1).Select

CopyWorksheetContent = True
End Function
---

FindLastRow returns 2 in the first and 53 in the second run when it stop at
the "Worksheets(strDestWorksheetName).Range(Cells(lngL astRow, 1), Cells
(lngLastRow + 52, 10)).PasteSpecial xlPasteAll" line returning "Error 1004 -
Application-defined or object-defined error"

And here's the even weirder part: This only happenes if I start the initial
Sub from a button on an Excel sheet. If I start the same Sub from within the
VBA Editor I don't get this error... and in some cases I can resume the
function by only clicking on the Play-button in the VBA Editor.


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run Time Error 1004 - Application-defined or object-defined error brent Excel Programming 2 October 3rd 05 05:23 PM
Run-time Error 1004: Application-defined or Object-defined Error Adrian Excel Programming 6 August 23rd 05 06:28 AM
Macro Run-time Error 1004 Application Defined or Object Defined Error Anddmx Excel Programming 6 June 9th 04 03:40 PM
Runtime Error 1004 -- Application Defined or Object Defined Error John[_51_] Excel Programming 3 September 4th 03 04:28 PM


All times are GMT +1. The time now is 06:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"