Hi,
Trying to create a macro to find a sheet (SheetName - dd/mm/yyyy) closest to todays date.
Code below only finds the sheet name within the quotes and not the format date.
I would also like to be able to select the sheet once the loop finds it.
so, if sheet is named 'SheetName - 01 Oct 2012' and it is run today it should find and select that sheet that is -2 days from today.
can anyone help please?
Trying to create a macro to find a sheet (SheetName - dd/mm/yyyy) closest to todays date.
Code below only finds the sheet name within the quotes and not the format date.
Code:
Sub Test()
Dim sh As Worksheet, flg As Boolean
Dim i As Integer
Dim lookUpSheet As String
i = 0
For Each sh In Worksheets
lookUpSheet = "SheetName - " + Format(Date - i, "dd mmm yyyy")
If sh.name = lookUpSheet Then flg = True: Exit For
i = i + 1
Next
If flg = True Then
MsgBox "Found! " & lookUpSheet
Else
MsgBox "unable to find " & lookUpSheet
End If
End Sub
I would also like to be able to select the sheet once the loop finds it.
so, if sheet is named 'SheetName - 01 Oct 2012' and it is run today it should find and select that sheet that is -2 days from today.
can anyone help please?