Ah... that would definitely cause it!

Your solution is certianly valid, however I would recommend something a little different. Rather than have different variable names, you can use the same ones - but with a tiny (and yet huge) change - instead of having the variables declared at the top of the form, have them declared in each sub where they are used (in both button_Click and Vals).

As it was previously, you were using the same variables - and overwriting them. Even with normal variables this is a bad thing, but with Object variables (Excel.Anything, ADODB.Anything, etc) this can be a nightmare, as you are losing your connection to the object (Excel), but it is still open using memory/CPU/... (check your Task Manager, or just wait until you shut your computer down - Excel will probably ask if you want to save!)

If you declare the variables just where they are used, you dont get any issues with them being overwritten by other code - which is easy to do accidentally as you add more parts to the application. Where variables are declared determines their Scope (where they can be used), and you should always try to keep the Scope as small as possible.