I have the following function that reads cells F23 thru Q38 but based on numbers 1 thru 12, 13 thru 24, 25 thru 36, 37 thru 48, or 49 thru 60 (5 year period) in F22 thru Q22 on many worksheets. Management changed from numbers, 1 thru 12, etc... to dates now based on fiscal year. Our fiscal year starts in August of each year.
What it does is that if you put a date in cell G8 (date based on the worksheet), cell F22 starts as that date for 12 months to Q22 per worksheet.
I need for this function to read dates (format mmm-yy) instead of numbers and I can't figure out. Can anyone help?
The function is:
[pre]
The above code is in each cell up to 60 months on a worksheet called HrsByMth. Because the fiscal year starts in August of each year, the first cell which is cell B1 of HrsByMth would be the start date of the project; so it won't be August all the time, it could be any date.
So I need to get "MonthNum " to match the heading dates on the worksheet HrsByMth.
If you have any other questions please let me know.
What it does is that if you put a date in cell G8 (date based on the worksheet), cell F22 starts as that date for 12 months to Q22 per worksheet.
I need for this function to read dates (format mmm-yy) instead of numbers and I can't figure out. Can anyone help?
The function is:
[pre]
Code:
Function HrsByMonth(strField As String, MonthNum As Integer) As Long
'Application.Calculation = xlCalculationManual
Dim sht As Worksheet, i As Long, j As Integer
HrsByMonth = 0
For Each sht In ActiveWorkbook.Sheets
If IsNumeric(Left(sht.Name, 2)) And IsNumeric(Right(sht.Name, 3)) And Mid(sht.Name, 3, 1) = "." Then
For j = 6 To 17
If CInt(sht.Cells(22, j)) = MonthNum Then
For i = 23 To 38 'update with max row
If sht.Cells(i, 5) = strField Then
HrsByMonth = HrsByMonth + CLng(sht.Cells(i, j))
GoTo nxtSht
End If
Next i
End If
Next j
End If
nxtSht: Next
'Application.Calculation = xlCalculationAutomatic
End Function[/pre]
The code is in a separate worksheet that gathers the information from each worksheet.
=(IF(ISBLANK($A2),0,(IF(ISBLANK(B$1),0,hrsbymonth($A 2,RIGHT(B$1,LEN(B$1)-6))))))
The above code is in each cell up to 60 months on a worksheet called HrsByMth. Because the fiscal year starts in August of each year, the first cell which is cell B1 of HrsByMth would be the start date of the project; so it won't be August all the time, it could be any date.
So I need to get "MonthNum " to match the heading dates on the worksheet HrsByMth.
If you have any other questions please let me know.