Hi gjsala,
I didn't check Skip's code. It's almost always right the first time, so there's no need. But, I do want to ask you, "Why"?
How long would you use Excel, if Excel did the same thing that you want to subject your end users to?
Imagine typing in Skip's code:
Code:
Dim r As Range, rng As Range, lLastRow As Long, ans As Variant
Do you really want r to be a Range?
You click
Yes
Do you really want rng to be a Range?
You click
Yes
Do you really want lLastRow to be a Long?
You click
Yes
Do you really want ans to be a Variant?
You would click
Yes again, but you slammed you're fist down so hard on the mouse after the last question that it no longer works.
Fun, huh?
How do you think the end users feel that have to use this code? How long are they going to continue using this spreadsheet as a solution to whatever problem it was intended to alieviate?
You probably have a perfectly good reason to force the users through this. But, is it going to work?
If you didn't get as frustrated as I would have, at some point you would quit examining what you had previously typed in, and would just click the
Yes button everytime the message popped up. My breaking point would be 3 or 4 times, because I could see what's coming. The end users may be 10, 20, 30 or more (the firsttime they use it). What's their breaking point after 10 times of using the spreadsheet (if they use it that many times)? Probably zero.
My point is, you need to code for any answers that seem out of bounds, and throw up the question at that point, or, simply refuse their entry as an answer, and let them know what is an exceptable answer.
I'll deny in court that I said this but, at some point you have to trust the end-user.