run time error 91, object variable or with block variable not set on MsgBox wsPivot.Name
watch on shows the function did not retrieve the codename.

If I end debugger and launch the code again from VBE or the quick launch button, it works, ad infinitum. It just does not work the first time. If I step back to the function and step through it, it also works, so tough to debug when it works on debug, just not on initial run.