Trying to reference another worksheet in active workbook

后端 未结 1 1165
心在旅途
心在旅途 2021-01-26 21:46

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 wa         


        
相关标签:
1条回答
  • 2021-01-26 22:06

    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.

    0 讨论(0)
提交回复
热议问题