So far in my many variations i can't get this to work so maybe the guru's here can pinpoint my obvious flaw in logic. This is an on open script that is supposed to scan the sheets within another workbook and skip a specific named sheet then add a formula to see if the date in the cell is greater then a year old (problem with the cell being blank returns true). If so then moves the scanned sheet into the starting workbook and then deletes the scanned sheet. [Summary: checks sheets to see if it is old then moves into another workbook and removes the original]
Thanx for any wisdom you can share.
' This code is used from one workbook "Archives 1.0.xls" on open and searches another workbooks sheets
Dim SlotArchive
Archive = Workbooks("Cabinet ID 1.0.xls").Worksheets.Count
For i = 1 to Archive
' Looks for the sheet name and skips if "Index"
if Sheets(i).Name <> "Index" then
' Unlocks the sheet
ActiveSheets.Unprotect Password = (Workbooks("Slot Array 3.5.xls").Worksheets("Intro").Range("U2")
' Selects cell S1 and places a formula to calculate if the number of days from the date in cell C4 to today exceeds 1 year
Sheets(i).Range("S1").Select
Selection.Clearcontents
Range("S1").Formula = "=Days360(C4,Today())"
' if the days are longer then 1 year, problem is if the cell is blank it always answers TRUE
and if Sheets(i).Range("S1").Value > "365" then
' Clears the previous formula
Range("S1").Select
Selection.ClearContents
' Copies the sheet and moves it to another workbook
ActiveWorkbook.Sheets(i).Copy
ActiveSheet.Move After:=Workbook("Archives 1.0.xls").Sheets("Index")
' Delets the old sheet from the previous workbook
Application.DisplayAlerts = FALSE
Workbooks("Cabinet ID 1.0.xls").Worksheets(i).Delete
Application.DisplayAlerts = TRUE
end if
end if
next i
Thanx for any wisdom you can share.
' This code is used from one workbook "Archives 1.0.xls" on open and searches another workbooks sheets
Dim SlotArchive
Archive = Workbooks("Cabinet ID 1.0.xls").Worksheets.Count
For i = 1 to Archive
' Looks for the sheet name and skips if "Index"
if Sheets(i).Name <> "Index" then
' Unlocks the sheet
ActiveSheets.Unprotect Password = (Workbooks("Slot Array 3.5.xls").Worksheets("Intro").Range("U2")
' Selects cell S1 and places a formula to calculate if the number of days from the date in cell C4 to today exceeds 1 year
Sheets(i).Range("S1").Select
Selection.Clearcontents
Range("S1").Formula = "=Days360(C4,Today())"
' if the days are longer then 1 year, problem is if the cell is blank it always answers TRUE
and if Sheets(i).Range("S1").Value > "365" then
' Clears the previous formula
Range("S1").Select
Selection.ClearContents
' Copies the sheet and moves it to another workbook
ActiveWorkbook.Sheets(i).Copy
ActiveSheet.Move After:=Workbook("Archives 1.0.xls").Sheets("Index")
' Delets the old sheet from the previous workbook
Application.DisplayAlerts = FALSE
Workbooks("Cabinet ID 1.0.xls").Worksheets(i).Delete
Application.DisplayAlerts = TRUE
end if
end if
next i