Excel VBA worksheet validation
Budget: $30 – $250 USD
I need Excel VBA program to validate the cells within a worksheet at they are entered, to ensure that they do not exceed maximum lengths. Could this be done using a Worksheet_Change sub? I am not sure. I have provided a sample XLS that you can look at, which gives good visual understanding of what needs to be accomplished. The validation rules would apply to all columns other than "A", which would be a control column and not a data column. The logic needs to work as follows. Maximum cell lengths for each column are going to be provided from a row that contains a string value of "LENGTHS" in column A. If no such row is found, then validation has been disabled and we just exit the entire process. There is nothing to be done. Otherwise, suppose data is entered into cell C6. When data is entered into a cell, we first want to look at column A for that row. If this cell (in this case, cell A5) has values of "*", "H", or "LENGTHS", then those specific string values indicate that this row is not a data line. Because this is not a data row, cells entered on this row do not need to be validated. No validation is to be done for this cell, so just move on. Otherwise, we have confirmed that we are on a data row, so we need to get the maximum length for cells in this column. As described earlier, these lengths will be defined on the row that contains "LENGTHS" in column A. This means that when data is entered into any given cell, we are always going to look towards the LENGTHS row to get the allowed maximum length for that particular column. In this case of our attached example, we would get the allowed maximum length for column C from cell C5 (since row 5 is the LENGTHS row). If the content of C5 is empty or not numeric, we again exit out of the validation for this cell, since lengths for this particular column are not to be checked. If C5 is present with a numeric value, then that cell value contains the maximum length for this column. We can then check the length of what is entered into C6 against the length obtained from C5. If the data entered into cell C6 exceeds the maximum length which is allowed for this column, then we message that the value entered into C6 is too long. The message should include the value cell address (C6), the value that was entered, the allowed maximum length for this column, and how many excessive characters were entered. The validation process should message and exit when the first problem is found, since that cell must be corrected by the user of the worksheet. Otherwise, the validation needs to continue and loop through all cells as data values are entered. This applies to all columns other than A, and all rows that do not have a value of "*", "H", or “LENGTHS” in column A.