using sheet code name to call Activate function

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,559
Hi
I have workbook which has worksheet called hello or sheet1(hello) that is how it looks like in the vba project window. The code below does not work because of
Code:
 Workbooks(1).Sheet1.Activate
but if I changed it to
Code:
 workbooks(1).worksheets("hello").Activate
it will work! Why is that? thank you very much
Code:
Sub create_ws_using_ws_collection()
    Dim x As Integer
    x = InputBox("for which book")
    Workbooks(x).Worksheets.Add after:=Sheet1
    Workbooks(1).Sheet1.Activate
End Sub
 

Some videos you may like

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
36,145
Office Version
365
Platform
Windows
To use the sheet codename, you do it like
Code:
Sheet1.Activate
But it only works for the workbook that contains the code.
 

Watch MrExcel Video

Forum statistics

Threads
1,090,459
Messages
5,414,643
Members
403,540
Latest member
mmorejon1215

This Week's Hot Topics

Top