Hi Everyone!
I think that my problem is relatively simple, I just can't visualize how to solve it. I need to create and excel function (SumMonth) which I pass 3 variable into.
1)Range of Dates in a column
2)Corresponding Range of $ Values in a column
3)Single Cell Range of Month to Sum for.
I have parts 1 and 3 done and can get it to count the number of occurances of a date in a range, I just can't figure out how to keep a running sum of the corresponding $ values.
Any help is appreciated!
Here is the Code I have so far...
_____________________________________________
Function GetMonth(test As String) As Integer
Dim FindMonth
If (test Like "*JANUARY*"
= "True" Then
GetMonth = 1
Else
GetMonth = 2
End If
End Function
______________________________________________
Function SumMonth(DateRange As Range, MonthRange As Range) As Integer
On Error GoTo errhandler
'Range1 as Month
'Range2 as NoteAmount
Dim intCellMonth As String
Dim intCountMonth As Integer
Dim Cell As Object
Dim CellMasterMonth As Object
Dim CellMonth As String
Dim test As String
'Get String of Month
For Each CellMasterMonth In MonthRange
test = CellMasterMonth.Value
intCellMonth = GetMonth(test)
For Each DateCell In DateRange
CellMonth = Format(DateCell.Value, "m"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Select Case CellMonth
Case intCellMonth
intCountMonth = intCountMonth + 1
End Select
Next DateCell
Next CellMasterMonth
SumMonth = intCountMonth
Exit Function
'-----------------------------------------------------
'Error Handler
errhandler:
MsgBox "You have encountered " & Err.Number & ", " & Err.Description
Exit Function
End Function
I think that my problem is relatively simple, I just can't visualize how to solve it. I need to create and excel function (SumMonth) which I pass 3 variable into.
1)Range of Dates in a column
2)Corresponding Range of $ Values in a column
3)Single Cell Range of Month to Sum for.
I have parts 1 and 3 done and can get it to count the number of occurances of a date in a range, I just can't figure out how to keep a running sum of the corresponding $ values.
Any help is appreciated!
Here is the Code I have so far...
_____________________________________________
Function GetMonth(test As String) As Integer
Dim FindMonth
If (test Like "*JANUARY*"
GetMonth = 1
Else
GetMonth = 2
End If
End Function
______________________________________________
Function SumMonth(DateRange As Range, MonthRange As Range) As Integer
On Error GoTo errhandler
'Range1 as Month
'Range2 as NoteAmount
Dim intCellMonth As String
Dim intCountMonth As Integer
Dim Cell As Object
Dim CellMasterMonth As Object
Dim CellMonth As String
Dim test As String
'Get String of Month
For Each CellMasterMonth In MonthRange
test = CellMasterMonth.Value
intCellMonth = GetMonth(test)
For Each DateCell In DateRange
CellMonth = Format(DateCell.Value, "m"
Select Case CellMonth
Case intCellMonth
intCountMonth = intCountMonth + 1
End Select
Next DateCell
Next CellMasterMonth
SumMonth = intCountMonth
Exit Function
'-----------------------------------------------------
'Error Handler
errhandler:
MsgBox "You have encountered " & Err.Number & ", " & Err.Description
Exit Function
End Function