ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deleting Worksheet Error (https://www.excelbanter.com/excel-programming/334939-deleting-worksheet-error.html)

James McDowell[_2_]

Deleting Worksheet Error
 
I am running through a loop and create/add a worksheet (sheet #1).
After placing all of the data on sheet #1 a second sheet (sheet #2) is
created/added and formulas are set on sheet #2 to read from sheet #1. The
calcs on sheet #2 are then copied and pasted as values, then I try to delete
sheet #1. When the activesheet.delete command is executed I get a "Cant read
memory error" and Excel is shut down.

How can I delete my newly created sheet without creating a catastrophic error?

Norman Jones

Deleting Worksheet Error
 
Hi James,

Post the problematic code.


---
Regards,
Norman



"James McDowell" wrote in message
...
I am running through a loop and create/add a worksheet (sheet #1).
After placing all of the data on sheet #1 a second sheet (sheet #2) is
created/added and formulas are set on sheet #2 to read from sheet #1. The
calcs on sheet #2 are then copied and pasted as values, then I try to
delete
sheet #1. When the activesheet.delete command is executed I get a "Cant
read
memory error" and Excel is shut down.

How can I delete my newly created sheet without creating a catastrophic
error?




James McDowell[_2_]

Deleting Worksheet Error
 
For Each wn In ActiveWorkbook.Sheets
If Right(wn.Name, 5) = "-DATA" Then
wn.Delete
End If
Next 'wn

Is there an inherent bug that you can not delete a worksheet created in code
until a certain condition is met?

"James McDowell" wrote:

I am running through a loop and create/add a worksheet (sheet #1).
After placing all of the data on sheet #1 a second sheet (sheet #2) is
created/added and formulas are set on sheet #2 to read from sheet #1. The
calcs on sheet #2 are then copied and pasted as values, then I try to delete
sheet #1. When the activesheet.delete command is executed I get a "Cant read
memory error" and Excel is shut down.

How can I delete my newly created sheet without creating a catastrophic error?


Norman Jones

Deleting Worksheet Error
 
Hi James,

The section of code you show is unexceptionable and I see no reason why it
might cause you problem.

Any code problem that there might be is likely to be upstream of this
section.

Is your problem reproducible, i.e. if you run the same code on another
workbook does the problem recur?

How can I delete my newly created sheet without creating a catastrophic
error?


Have you tried copy sheet # 2, and any other sheets, to another workbook and
then trashing the original workbook?


---
Regards,
Norman



"James McDowell" wrote in message
...
For Each wn In ActiveWorkbook.Sheets
If Right(wn.Name, 5) = "-DATA" Then
wn.Delete
End If
Next 'wn

Is there an inherent bug that you can not delete a worksheet created in
code
until a certain condition is met?

"James McDowell" wrote:

I am running through a loop and create/add a worksheet (sheet #1).
After placing all of the data on sheet #1 a second sheet (sheet #2) is
created/added and formulas are set on sheet #2 to read from sheet #1.
The
calcs on sheet #2 are then copied and pasted as values, then I try to
delete
sheet #1. When the activesheet.delete command is executed I get a "Cant
read
memory error" and Excel is shut down.

How can I delete my newly created sheet without creating a catastrophic
error?





All times are GMT +1. The time now is 12:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com