UPDATE: I created a new project, re-created the sheet and copied in the code, and it worked fine from the button. I don't understand why it was calling a random function, however.