The following code runs but it keeps giving me YTD(year to date values.) I don't want that. I want to be able to display
the sum of all category values from the first day of each month. Below is the Sheet named AOS whose category values are in col B, date values in col C
and amounts to be totaled for each category from month to date in col E. Here is the code:
I wrote this code and can't fiugre out why its still giving me YTD category totals instead of MTD category totals.
Any help is greatly appreciated. BTW I prefer not to use an advanced autofilter if possible.
I'm not yet up to speed in understanding whether using the =SUMIFS formula can do this or not. The result is displayed in a userform with the total values of each
MTD category in a oolumn to the right of each category.
Thanks for any help. , cr
the sum of all category values from the first day of each month. Below is the Sheet named AOS whose category values are in col B, date values in col C
and amounts to be totaled for each category from month to date in col E. Here is the code:
Code:
Sub MTDAOSTOTALSBYCAT()
Dim DynamicRange As Range
Dim d1 As Date, d2 As Date, strDATE As Date
Dim wb As Worksheet, ws As Worksheet ' do you need this line?
Dim t As Currency ' do as above?
Dim a, i As Long, x, n As Long
'new code
d1 = Date
d1 = DateSerial(Year(d1), _
Month(d1), 1)
MsgBox d1
d2 = Date
NewReport.DTPicker1.value = d1
NewReport.DTPicker2.value = d2
Application.EnableEvents = False
Application.ScreenUpdating = False
a = Sheets("AOS").Range("A1").CurrentRegion.value
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 1 To UBound(a, 1)
If a(i, 3) >= d1 And a(i, 3) <= d2 Then
.Item(a(i, 2)) = .Item(a(i, 2)) + a(i, 5)
End If
Next
x = Array(.keys, .Items): n = .count
End With
If n > 0 Then
Sheets("REPORT").Range("A2").Resize(n, 2).value = _
Application.Transpose(x)
Else
MsgBox "No data in date range"
End If
Worksheets("REPORT").Select 'new code to total values
Range("B2").Select
Set DynamicRange = Range(Selection, Selection.End(xlDown))
DynamicRange.Name = "mytotal"
Range("mytotal").End(xlDown).Select
ActiveCell.Offset(2, 0).Select
ActiveCell.value = "=SUM(mytotal)"
ActiveCell.Select
Selection.NumberFormat = "$#,##0.00"
ActiveCell.Offset(0, -1).Select
ActiveCell.value = "Totals"
Application.EnableEvents = True
Application.ScreenUpdating = True
AOSTOTBYCAT.Show
AOSTOTBYCAT.TextBox1.value = ActiveCell.value
AOSTOTBYCAT.TextBox1.Text = Format(AOSTOTBYCAT.TextBox1.Text, "$ #,##0.00")
AOSTOTBYCAT.Caption = "MTD AOS Totals By Category"
Sheets("BUDGET").Select
End Sub
I wrote this code and can't fiugre out why its still giving me YTD category totals instead of MTD category totals.
Any help is greatly appreciated. BTW I prefer not to use an advanced autofilter if possible.
I'm not yet up to speed in understanding whether using the =SUMIFS formula can do this or not. The result is displayed in a userform with the total values of each
MTD category in a oolumn to the right of each category.
Thanks for any help. , cr