+ Reply to Thread
Results 1 to 3 of 3

Activate a Worksheet based on Variable

  1. #1
    Forum Contributor
    Join Date
    01-06-2011
    Location
    cleveland
    MS-Off Ver
    Excel 2007
    Posts
    225

    Activate a Worksheet based on Variable

    I have a worksheet labeled '2008'

    Please Login or Register  to view this content.
    what I want to do is if a variable (SelectedYear) = 2008 then execute the code above. I know i am missing the quotations required to reference the worksheets as

    Please Login or Register  to view this content.
    works fine. What would be the correct syntax to do what I am looking to do? I would like to structure it this way as I have many years worth of worksheets to code for this way and I am looking to reduce the number of Sheets("n") to code

  2. #2
    Forum Contributor
    Join Date
    01-06-2011
    Location
    cleveland
    MS-Off Ver
    Excel 2007
    Posts
    225

    Re: Activate a Worksheet based on Variable

    Please Login or Register  to view this content.
    The double quotations escaped the quote and functions as desired

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Activate a Worksheet based on Variable

    2008 on it's own will be treated as the workbook index, not name.

    Try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Activate worksheet based on a column value selected from validation list
    By jnbroek in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-11-2013, 11:05 PM
  2. [SOLVED] Worksheet does not become the active 1 using .Activate function based on MsgBox response
    By thelisa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-15-2013, 04:55 PM
  3. [SOLVED] Combining worksheet custom (Name) Property with a variable to activate sheet
    By Jon F in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-28-2013, 03:11 PM
  4. Replies: 3
    Last Post: 10-10-2012, 05:10 PM
  5. [SOLVED] Can a variable be used in a Worksheet().Activate method
    By Brad Sumner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-12-2005, 03:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1