Link to home
Start Free TrialLog in
Avatar of andy7789
andy7789

asked on

VBA Excel: Clear thecontent of spreadsheet

Hi X-perts,

I am using

Set Wcurr = ThisWorkbook.Worksheets("test")
Wcurr.Cells.Clear

The worksheet "test" is hidden. Sometimes, the worksheet is not cleared..... I cannot find the reason, though tried to debug it many times - step-by-step.

What could prevent worksheet of being cleared?

Thanks
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)
Flag of United States of America image

Are you sure the code is always run? Under what conditions is it not cleared? Can you reproduce? Is the worksheet protected in any way?

Kevin
Avatar of andy7789
andy7789

ASKER

HI Kevin,

it would be an easy task, if I could determine the exact conditions. It happens from time to time.. It DOES run the code, because I can see both the new content and the old as well.

The worksheet is not protected.....It happens only after I run a lot of other macros, stochastic simulations etc. None of these macros are supposed to touch that spreadsheet.

Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of zorvek (Kevin Jones)
zorvek (Kevin Jones)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you guys,

I have tested a lot of things with no success at all. The only solution that seems to be working 100% is to delete a sheet and add a new one. Since excel doesn't delete names when deleting sheets, I have to delete all names with #REF.

still, it is a mystery for me, but I cannot understand what the problem with .cells.clear could be. Typically, it happens after a "heavy" excel application use, but I am not able to spot the pattern.
Since you didn't answer any of my questions, I can't be much more specific, but of you are running 2003 and it is the bug I mentioned, there is a hotfox available; if you are on 2007, there isn't yet.
Sorry...

I am running Excel 2007 SP2
The content of all cells appears in the formula bar .
The only symptom is that a new content overwrites the old one.

Also, when writing a new content, it doesn't change range names, i.e. the names are the same as of old content.

The result of this mess is:

a) new content is written over old content
b) names are not changed as should be when writing new content (under normal conditions old names are replaced by new ones)

That's it...