updating a cells formula using VBA code
Posted by Rees Macleod on September 13, 2000 8:14 PM
I posted this question earlier this month, but no one responded yet. I don't know if it is too hard or too poorly worded. Please let me know if it is; otherwise, it is very immportant to me to find an answer to it...if anyone has any idea how to do it I would really appreciate any ideas. Thanks again. Here is the problem
I have a spreadsheet that has a user defined number of sheets in it. When they specify the number of sheets I then programmaticaly fill in all the formulas and labels in each cell for each sheet. The problem comes in when someone deletes a sheet, since the top sheet adds values from all the sheets in the workbook. Naturally, I get the REF error as the sheet is no longer there.However, I do not want the people to have to adjust the formula. Is there a way to update the formula to remove the REF error in the formula?
here is an example:
If the formula in a cell was this:
=C17+Sheet1!E20+Sheet2!F22+Sheet4!G21
And someone deletes Sheet2
it leaves this:
=C17+Sheet1!E20+#REF!F22+Sheet4!G21
Can I get rid of the +#REF!F22 part that is now causing the error using code that is tripped when the sheet is deleted?
Thank you in advance for any ideas you might have.
Rees