2

In the ongoing project of mine, with which I'm about to be done, I want to make sure that the people taking over my job will be left with something that won't break after I'm gone. This project is an ongoing tracker kept daily throughout the year and each worksheet used (several for varying items of interest) are separated out by year in the name of the worksheet. For instance, the primary sheet is simply called 'YYYY' in which the 'YYYY' is the current year. Other worksheets are called, 'DTDYYYY', 'MTDYYYY', 'YTDYYYY' in which the YYYY is the current year. Come 2013, I'd like it if the little VBA that I use is able to take the current YYYY and find the appropriate worksheets automagically.

I know that I can reference sheets using the SheetIDX convention. I know that I can use Sheets(NAME) method. I'm not so sure how to best go about accomplishing my goal, though.

2
  • 2
    Your requirements are not clear. If you wish to find a worksheet that you know is called 2013, where is the difficulty? Do you mean you wish to create a worksheet? What happens at the moment? Commented Jan 7, 2012 at 9:19
  • 1
    I need to be able to dynamically use worksheets, based on the current year, that currently exist. The difficulty is that I don't know how to do it. Commented Jan 7, 2012 at 18:04

2 Answers 2

7
Application.Sheets("Sheet1").Index
Application.Sheets(1).Name

Hope this is what you needed.

Sorry, I didn't see the last part about current year. Perhaps this?

Application.Sheets(Year(Date())).Activate
Sign up to request clarification or add additional context in comments.

1 Comment

This is going the right direction for what I'm seeking. However, when use these methods, I get the error, Subscript out of range (err #9). I also tried by assigning year(date) to a variable and using that. I get the same error. I'm currently using Excel 2007. TIA!!
6

You need a string for the name.

With ThisWorkbook
    .Sheets(CStr(Year(Date))).Select
End With

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.