Hi guys, Does anyone have any tips to share on defensive programming in Excel.
Personally I always (nearly always) use an on error goto error_handler which includes things like
application.screenupdating = true
application.calculations = xlautomatic
application.displayalerts = true
What else would you put into your error handler.
Do you define public variables for application current state (e.g. application.visible, activecell, activesheet, activeworkbook, calculations etc) so that you can reset to prior values on completion of your procedure
how do you defend against unexpected values in worksheets; e.g. a rogue value beyond the end of the expected usedrange, numbers stored as text instead of numbers (screws up VLOOKUP for a start...), Column headings not being in the expected column numbers, Worksheets being left in a filtered state.
When defining variable sized ranged do you tend to go for .end(xlDown), .UsedRange or .specialcells(xlCelltypeLastCell) and why
what is your preferred range notation any why
I mainly use Range(Cells(x,y),Cells(x2,y2)) because I find it easier to substitue the row/column numbers with variable values or append modifiers such as .End() or .Offset()
Do you automtically defend against issues or only if the exceptional condition occurs?
What errors have you come across where you have ended up in a WTF! moment and how did you program around them.
Personally I always (nearly always) use an on error goto error_handler which includes things like
application.screenupdating = true
application.calculations = xlautomatic
application.displayalerts = true
What else would you put into your error handler.
Do you define public variables for application current state (e.g. application.visible, activecell, activesheet, activeworkbook, calculations etc) so that you can reset to prior values on completion of your procedure
how do you defend against unexpected values in worksheets; e.g. a rogue value beyond the end of the expected usedrange, numbers stored as text instead of numbers (screws up VLOOKUP for a start...), Column headings not being in the expected column numbers, Worksheets being left in a filtered state.
When defining variable sized ranged do you tend to go for .end(xlDown), .UsedRange or .specialcells(xlCelltypeLastCell) and why
what is your preferred range notation any why
I mainly use Range(Cells(x,y),Cells(x2,y2)) because I find it easier to substitue the row/column numbers with variable values or append modifiers such as .End() or .Offset()
Do you automtically defend against issues or only if the exceptional condition occurs?
What errors have you come across where you have ended up in a WTF! moment and how did you program around them.