Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Runtime Error 13 with Worksheet.Delete

Why does the following code produce an error 13 (Excel 2007) after the sheet
is deleted and when the end function statement is executed?

Public Function SheetDelete(varSheet As Variant) As Boolean

' var sheet is the sheet object to delete, not the index or name

SheetDelete = varSheet.Delete

End Function

The sheet is deleted but the runtime error occurs. The function returns the
correct value of the delete.

Any thoughts would help.
--
WEW
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Runtime Error 13 with Worksheet.Delete

On Oct 16, 7:31*pm, AlForester
wrote:
Why does the following code produce an error 13 (Excel 2007) after the sheet
is deleted and when the end function statement is executed?

Public Function SheetDelete(varSheet As Variant) As Boolean

* * ' var sheet is the sheet object to delete, not the index or name

* * SheetDelete = varSheet.Delete

End Function

The sheet is deleted but the runtime error occurs. The function returns the
correct value of the delete.

Any thoughts would help.
--
WEW


I have tested your code and did not receive any errors, my thinking
would be that the type mismatch error is coming from the function call
hence why its getting to the bottom of the function before erroring,
how are you calling the function? The other thing to note is the
function is declared to return a boolean but as it just deletes the
sheet then the function will return nothing.

James

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Runtime Error 13 with Worksheet.Delete

Just a guess...

Maybe excel is recalculating and there's a calc event firing.

I'd try:

application.enableevents = false
on error resume next 'in case it can't be deleted
varsheet.delete
if err.number < 0 then
err.clear
sheetdelete = false
else
sheetdelete = true
end if
on error goto 0
application.enableevents = true

======
In fact, I'd try this variation (without the .enableevents lines)--just to see
if that worked.




AlForester wrote:

Why does the following code produce an error 13 (Excel 2007) after the sheet
is deleted and when the end function statement is executed?

Public Function SheetDelete(varSheet As Variant) As Boolean

' var sheet is the sheet object to delete, not the index or name

SheetDelete = varSheet.Delete

End Function

The sheet is deleted but the runtime error occurs. The function returns the
correct value of the delete.

Any thoughts would help.
--
WEW


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Runtime Error 13 with Worksheet.Delete

varSheet.Delete
does that returna true/false? this is a boolean function after all





"AlForester" wrote:

Why does the following code produce an error 13 (Excel 2007) after the sheet
is deleted and when the end function statement is executed?

Public Function SheetDelete(varSheet As Variant) As Boolean

' var sheet is the sheet object to delete, not the index or name

SheetDelete = varSheet.Delete

End Function

The sheet is deleted but the runtime error occurs. The function returns the
correct value of the delete.

Any thoughts would help.
--
WEW

Reply
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
error runtime 9: deleting a worksheet [email protected] Excel Programming 4 April 7th 05 04:42 PM
Set worksheet range runtime error 1004 DaveP Excel Programming 1 March 29th 05 07:13 AM
getting runtime error when trying to delete records SM Excel Programming 1 April 16th 04 09:11 PM
runtime error '1004' delete Method of Range Class Failed Tom Kennedy Excel Programming 0 April 14th 04 08:08 PM
runtime error '1004' delete Method of Range Class Failed Tom Ogilvy Excel Programming 0 April 1st 04 04:09 AM


All times are GMT +1. The time now is 06:16 PM.

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

About Us

"It's about Microsoft Excel"