How to activate a specific worksheet in Excel?

后端 未结 3 796
挽巷
挽巷 2020-12-13 08:33

I just need to activate a certain worksheet. I have a string variable that keeps the name of the worksheet.

相关标签:
3条回答
  • 2020-12-13 08:46

    Would the following Macro help you?

    Sub activateSheet(sheetname As String)
    'activates sheet of specific name
        Worksheets(sheetname).Activate
    End Sub
    

    Basically you want to make use of the .Activate function. Or you can use the .Select function like so:

    Sub activateSheet(sheetname As String)
    'selects sheet of specific name
        Sheets(sheetname).Select
    End Sub
    
    0 讨论(0)
  • 2020-12-13 08:57

    An alternative way to (not dynamically) link a text to activate a worksheet without macros is to make the selected string an actual link. You can do this by selecting the cell that contains the text and press CTRL+K then select the option/tab 'Place in this document' and select the tab you want to activate. If you would click the text (that is now a link) the configured sheet will become active/selected.

    0 讨论(0)
  • 2020-12-13 09:05

    I would recommend you to use worksheet's index instead of using worksheet's name, in this way you can also loop through sheets "dynamically"

    for i=1 to thisworkbook.sheets.count
     sheets(i).activate
    'You can add more code 
    with activesheet
     'Code...
    end with
    next i
    

    It will also, improve performance.

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