When I see this, I expect to see that arraytest is probably typed as a Range object variant rather than a variant containing a VBA array. Run this modification (all I did was add a stop statement)
When it gets to the Stop and brings up debug mode, look in the locals window or set a watch for Typename(arraytest) or add a debug.print typename(arraytest) or other strategy to see what type arraytest is.
What are you trying to get from the Ubound() function? Usually I am trying to get a count of how many cells are in the range object, so I often use val=arraytest.Count instead of UBound.
Does arraytest need to be able to handle both range object and VBA array inputs? You might need a block IF() at the top of the procedure that detects what data type arraytest is and choose the appropriate course of action.
I sometimes find it valuable to be more specific when typing input arguments. In this case, if you only ever plan to pass Excel ranges to the function, type arraytest as a Range object (arraytest as Range), which will make it more clear to you in your code that arraytest is not a VBA array.
In short, I think the problem is a data type problem -- UBound cannot tell what the upper index of an Excel range is. The final solution to the problem depends on exactly how you need the procedure to work with arraytest.
Bookmarks