ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   how to find the operating syetem year in vba (https://www.excelbanter.com/new-users-excel/218466-how-find-operating-syetem-year-vba.html)

DarkNight

how to find the operating syetem year in vba
 
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


Gary''s Student

how to find the operating syetem year in vba
 
This will give you the current year:

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

Is this what you need?
--
Gary''s Student - gsnu200829


"DarkNight" wrote:

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


DarkNight

how to find the operating syetem year in vba
 
yes thank you, for some reason i always try to make things very complicated.

"Gary''s Student" wrote:

This will give you the current year:

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

Is this what you need?
--
Gary''s Student - gsnu200829


"DarkNight" wrote:

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



All times are GMT +1. The time now is 08:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com