I am trying to make another worksheet active when command button is clicked, but I'm staying within the same active workbook:
Sub Submit_Warranty()
'Set warranty data worksheet as active page
Sheets("Sheet2").Activate
'Show the submit warranty user form
Warranty_Input.Show
End Sub
I keep getting "subscript out of range" error. Any ideas?
If the code you posted is everything, then that error pretty much has to be from an invalid reference. So my guess would be that the actual displayed name is something like "Warranty_Data", while "Sheet2" is likely the VBA object name (maybe you're using them in reverse).
There are a lot of ways to select a worksheet, with various advantages and disadvantages. When it comes to selecting by name, the major gotcha to watch out for is that sheets actually have two names assigned, and you're employing both methods of selection in the code you posted. The one name is what's displayed in the sheet's workbook tab, the other name is internal to VBA. Here's a screenshot to demonstrate how to use both types of names.
来源:https://stackoverflow.com/questions/33479352/trying-to-reference-another-worksheet-in-active-workbook