Date of Beginning of Month = Date of Start of month
date of Last thirty 30 days
First of year date
This date last month
Function BOM(dDate As Date) As Date
'Thanks to xld @ http://www.vbaexpress.com/forum/showthread.php?49493
'Beginning Of Month
BOM = dDate - Day(dDate) + 1
'How it Works:
' if dDate = 24 Mar, 2014
' Day(dDate) = 24: dDate - 24 = 0 Mar,2014
' Add 1 = 1 Mar, 2014
End Function
Function BOY(dDate As Date) As Date
'Beginning Of Year
Dim sYear As String
sYear = CStr(Year(dDate))
BOY = CDate("1/1/" & sYear) 'Already international
End Function
Function Last30Days(dDate As String) As Date
'The Date 30 days ago. March 1st = Jan 29; Jan 31 = Jan 1st
Last30Days = dDate - 30
End Function
Function PreviousMonth(dDate As Date) As Date
'Returns proper date of previous month. Mar 1st = Feb 1st; Mar31 = Feb 28 (29 on leap years)
PreviousMonth = DateAdd("m", -1, dDate)
End Function
Sub Test()
'Range("D1") holds date to use
Dim TotalThisMonthToDate
Dim StartRow As Long
Dim EndRow As Long
Const XXX As Long = 99 'Random column number
With Sheets("YTD")
StartRow = .Range("A:A").Find(BOM(.Range("D1")), LookIn:=xlValues).Row
EndRow = .Range("A:A").Find(.Range("D1").Value, LookIn:=xlValues).Row
TotalThisMonthToDate = WorksheetFunction.Sum(Range(Cells(StartRow, XXX), Cells(EndRow, XXX)))
End With
End Sub