Look Up sheets

G

Greg B

I am trying to work out a little code that will look up what month and year
it is, then once it has this activate the sheet that is using the month and
year as the sheet name.
if it is not in the sheets i want it to copy a sheet called "template" and
then rename the sheet using the month and year.

Thanks

Greg B
 
B

Bob Phillips

Private Sub Workbook_Open()
Dim Lookup As String
Dim ws As Worksheet

Lookup = Format(Date, "mmmyyyy")
On Error Resume Next
Set ws = Worksheets(Lookup)
On Error GoTo 0
If Not ws Is Nothing Then

ws.Activate
Else

Worksheets.Add(after:=Worksheets(Worksheets.Count)).Name = Lookup
End If
Set ws = Nothing
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top