Hello, my first post here, forgive me if I overlook some convention. I'll try to be as concise and clear as possible.
I have a worksheet I use as an invoice. Some columns in the invoice have data validation to let the user pick values. I have a number of macros, one of which cleans up the sheet to correct issues resulting from cutting/pasting or other careless use of the invoice. Part of that cleanup macro makes sure the data validation of the columns is correct.
The validation list source for one of the columns is on a different worksheet, with this formula:
At this point I'm assuming that the validation is currently unmolested and correct in the last cell of the column, and I want to make all of the cells in the column have the same validation. Here's the code I use (starting with "oValidation" being set to the .Validation property of the last cell in the column, and "oCol" being the range representing the entire invoice column in question):
Should work, right? Doesn't. I get no errors, but the validation formula does not get set correctly on two levels. As I step through the code and step past the "...Validation.Add" line, ".Formula1" shows "=Parameters!$B$50:$B$58" but "oTempRange.Validation.Formula1" is only "=$B$50:$B$58" (in other words, it drops the sheet reference). Moreover, when I have a cell within that range selected, and type this in the immediate window:
I get the following error:
---------------------------
Microsoft Visual Basic for Applications
---------------------------
Run-time error '1004':
Application-defined or object-defined error
---------------------------
OK Help
---------------------------
... which is the error it gives when the range in question does not have validation. Just to be sure, when I select the last cell in the column and then execute the same line in the immediate window, it gives the correct "=Parameters!$B$50:$B$58".
Why is there this disconnect between oTempRange and Selection, when the selected cell is certainly within the oTempRange at the time?
Why is the oTempRange validation formula missing its sheet reference?
And most importantly, why is the validation not being set when I do this, and how do I get it to be set correctly?
Thank you for reading this, and please let me know if I left out any information you need to help me!
-Dan
Bookmarks