how to find the operating syetem year in vba

D

DarkNight

Hello, i need to find out what the o.s. year is in vba so that i can delete
tab on a sheet.
my sheet has several tab, some which i don't want to delete like "ledger"
"2008" and the current year "2009" if i add extra years i would like to be
able to delete years "2010" + i have some code wich add the years to my
sheet which basicaly copys previous years and clears all the contents and
renames it to the next year, in doing so it all so adds various totals to my
"ledger" sheet.

For Each sh In Sheets
If sh.Name = "Ledger" Then GoTo skip
If sh.Range("A1").Value > NewYear Then _
NewYear = sh.Range("A1").Value
skip:
Next sh

'Select Lastest Year
Nsh = CStr(NewYear)
'''' change this year every year '''
If Nsh = "2008" Then End
''''''''''''''''''''''''''''''''''''
Sheets(Nsh).Select

'Add and rename new sheet
Worksheets(Nsh).Delete
so its this line if Nsh = "2008" then end that i need to auto update.

please help, thanks in advance
 
G

Gary''s Student

This will give you the current year:

Sub dural()
NewYear = Year(Date)
MsgBox (NewYear)
End Sub

Is this what you need?
 

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