I seem to have a dilemma. I have an EXCEL 2003 template which users should use to fill in tabular information. I have validations on various cells and each row undergoes a rather complex VBA validation upon change and selection_change events. The sheet is protected to disallow formatting activities, insert and delete of rows and columns, etc.
As long as users fill in the table row by row, all works pretty fine. Things get worse if I want to allow user to copy/paste data into that sheet (which is a legitimate user demand in this case), because cell validation would disallow paste actions.
So I tried to allow users to turn off protection and cut/paste, a VBA marks the sheet to indicate the fact that it contains unvalidated entries. I have created a “batch validation” that validates all non-empty rows at once. Still copy/paste doesn’t work too well (must directly jump from source sheet to destination, cannot paste from text files, etc.)
Cell Validation is also not good from the point of inserting rows, because depending on where you insert the row, cell validation may be missing completely. And if I copy cell validations down to row 65k the empty sheet gets over 2M in size – another most unwanted side effect.
So I thought one way to circumvent troubles would be to forget about cell validation alltogether and use only VBA. Then I would sacrifice user comfort of providing drop-down lists in some columns – some of which change as a function of entries in other columns, too.
Has anyone been in the same situation before and can give me some (generic) tactical advises (coding VBA is not a problem)?
Kind regards
MikeD
Here is what I came up with (all Excel 2003)
All sheets in my workbook requiring complex validation are organized in tabular form with a couple of header lines containing sheet title and column titles. All columns right of the last are hidden, and all rows below a practical limit (in my case 200 rows) are hidden as well. I have set up the following modules:
all sheets
particular to a single sheet
The Enums purely serve the purpose of avoiding to hardcode; should I want to add or remove columns I mostly edit the Enums, while in the real code I use the symbolic names for each column. This may sound a bit over-sophisticated, but I learned to love it when users came for the 3rd time and asked me to modify the table layouts.
First I describe code which is event triggered.
Suggestions in this thread was to trap PASTE activities. Not really supported by an event trigger in Excel-2003, but finally not a big miracle. Trapping/Untrapping the PASTE occurs on activate/deactivate events in Sheet_X. On Deactivate I also check protection status. If unprotected I ask the user to agree to a batch validation and re-protect. Single Line validation and Batch validation routines then are code objects in module Sheet_X_Functions described further down.
Module Sheet_X_Functions basically contains the validation Sub’s specific to that sheet. Note the use of Enum’s here – it really paid off for me – especially in the Sheet_X_ValidateRow routine – users forced me to change this a felt 100 times 😉
supporting Sub’s / Functions in module CommonFunctions that are called from the above code
One important thing is the Selection_Change. If the sheet is protected, we want to validate the line the user has just left. Therefore we have to keep track of the row number where we were coming from, as the TARGET parameter refers to the NEW selection.
If unprotected, the user could jump into the header rows and start messing around (allthough there are cell locks, but ….), so we just let not place him/her the cursor there.
There is a Worksheet_Change code as well in Sheet_X, where I dynamically load values into the drop-down lists of fields of the current row based on the entry of other cells. As this is very specific, I just present the frame here, Important to temporarily suspend event processing to avoid recursive calls to the Change trigger
That’s about it …. hope this post is usefull for some of you guys
Good luck MikeD