I am taking inputs from the user for which I am giving him choice..
For eg in column “conductor” he is given a choice “Al or Cu”
Similarly in column “insulator” he is given a choice “XLPE or PVC”
Now the above two are simple versions of lists I am giving to the user, but some of my lists depend on previous inputs and for that I am using datavalidation like this:
=indirect($C5 & "_" & $D5)
(A named range for eg: al_xlpe)
Assuming column C and D refer to some inputs (This will lead to 2! named ranges being defined earlier).
Because of the above method I have been forced to use a lot of named ranges( some of my validation list choices depend on over 4 or more inputs, they go like this:
=indirect("col6" & "_" & col7 & "_" & col8 & "_" & col9)
(another named range for eg: al_xlpe_duct_3;there can be 4! of these)
There are several problems I am facing:
- Since databases can expand anytime for validation lists consisting of over 4 inputs will require 4! named range changes.
- Data validation is easily lost(A major problem)
- I cant restrict copy and paste since most of my users will be pasting data from other sheets(Cant use import since columns will never be fixed)
- I cant use list boxes since any number of rows of data can be entered and i require choice in each row
- Can’t use MS Access for database management because my tool kind of works on input data and most of my users arent familiar with access(moreover it doesnt allow easy copy pasting of data)
Is there a better method?
In this answer, I offer a technique that was very popular when I started work as a programmer 45 years but which I have not seen used in a regular application by anyone but myself in many years. We had borrowed the technique from compiler development but used it much less formally.
In the full blown technique, there would be five steps:
Not all five steps were required for every problem; sometimes the human and fast-processing formats could be the same. This may sound complicated but it allowed us to solve many complex problems easily and efficiently.
In the worksheet below, I have encoded my understanding of the type of validation you require.
In row 2, I declare that a cell in column C may take a value of V1 or V2 or V3 or V4.
In row 3, I declare that a cell in column D may take a value of V5 but only if column C of the same row has a value of V1 or V2.
In row 4, I declare an alternative value for a cell in column D with its own set of conditions.
In row 5, I declare that a cell in column E may take a value of V7 or V8 but only if column D of the same row has a value of V5 and column C of the row has a value of V1.
I do not have enough of an understanding of your requirement to know if this is the best or a complete representation of your validation requirements. However, I hope you get the idea and can develop a convenient representation of your requirement if you like this technique.
Next I need to define the fast-processing form of this specification. I have designed four tables and implemented the code below which converted the human worksheet format to the fast-processing format then output the contents of those tables to the immediate window ready to be placed in this answer:
There are three columns for which there are validation rules in the worksheet which are columns 3 (C), 4 (D) and 5 (E). The above table tells us that for column 3 (C), rules 1 to 1 apply and for column 5 (E), rules 4 to 7 apply.
For Rule 1, conditions 1 to 0 apply, that is there are no conditions. The permitted values are entries 1 to 4 (V1, V2, V3 and V4) in the Value table. This corresponds to row 2 in the worksheet.
For Rule 4, the permitted values are entries 11 and 12 (V7 and V8) in the Value table providing conditions 3 to 4 apply. Condition 3 is that column 4 (D) must equal entry 13 (V5) in the Value table. Condition 4 is that column 3 (C) must equal entry 14 (V1) in the Value table. This corresponds to row 5 in the worksheet.
If you are not used to thinking about controlling code via linked tables, this may take a little time to understand fully. I have followed the links for a couple of rules. Try a few more and you will get the idea. Notice how the worksheet was designed to be easy for a human to mantain whereas these tables are designed for fast execution by a computer.
This compilation process could be within a Worksheet Open routine or you could pre-compile and store the tables in the workbook. These tables are ready for execution by a Worksheet Change routine or they could be used to calculate and place formulae in appropriate cells.
I hope I have explained this well enough for you to get the idea and to decide if this technique is appropriate for your problem. Could back with questions as necessary and I will expand the explanations.
The following code convert the human format to the fast processing format and then outputs the fast processing format to the immediate window.
End Sub