I had a behavioral problem with .SpecialCells(xlCellTypeConstants) method that just erased all of the data in one of my spreadsheets today.
I have been using the code for months with no undesired behavior until today. I have done a lot of debugging on this and managed to strip down the errant code to a very simple example that generates the problem behavior every time in a freshly created spreadsheet.
A B C 1 text 2 text 3 4 text 5
using a spreadsheet like the simulated one shown above
will print "$A$1,$B$2,$C$4" in the immediate window![]()
Please Login or Register to view this content.
while
will print "$A$1" as expected and![]()
Please Login or Register to view this content.
will generate "Run-time error '1004': Application-defined or object-defined error" as expected.![]()
Please Login or Register to view this content.
It appears that every time an object refers to a single cell and the special cells method is applied to it, the new object returns all constants on the spreadsheet.
Has anyone run into this problem before and figured out a work around for it?
Since I was referencing a single cell today (for the first time) with the special cells method and the line of code just happened to end with .ClearContents the code very efficiently wiped out all of my constant cells in the spreadsheet.
Any insights or ideas will be greatly appreciated,
Thanks,
Bookmarks