Excel 2016 - VBA - Date search allowing 2 digit and 4 digit year it searches for. right now if i enter 3/1/2022 or 3/1/22 still only searches 3/1/2022.
Private Sub btnGenerate_Click()
'On Error GoTo ErrorHandler
lblMessage.BackColor = ColorConstants.vbGreen
lblMessage.Caption = "Now, generating the report !!!"
Dim strFromDate As String
Dim strToDate As String
Dim aFromDate As Variant
Dim aToDate As Variant
Dim dtFromDate As Date
Dim dtToDate As Date
Dim dtCheckDate As Date
Dim sRLFilePath As String
Dim sCLFilePath As String
'Dim dRLMaxRows As Double
'Dim dCLMaxRows As Double
Dim strSearchDate As String
Dim oReportWorkbook As Workbook
Dim oReportWorksheet As Worksheet
Dim oWorkbook1 As Workbook
Dim oWorkbook2 As Workbook
Dim iReportRowIndex1 As Double
Dim iReportRowIndex2 As Double
strFromDate = txtFromDate.Value
strToDate = txtToDate.Value
aFromDate = Split(strFromDate, "/")
aToDate = Split(strToDate, "/")
dtFromDate = DateSerial(aFromDate(2), aFromDate(0), aFromDate(1))
dtToDate = DateSerial(aToDate(2), aToDate(0), aToDate(1))
dtCheckDate = dtFromDate
sRLFilePath = txtRLFilePath.Value
sCLFilePath = txtCLFilePath.Value
Application.Interactive = False
Set oReportWorkbook = ActiveWorkbook
Set oReportWorksheet = ActiveSheet
'Set oWorkbook1 = Workbooks.Open("D:\Country&LocalReport\2022 - ECT - Real Estate.xlsx")
'Set oWorkbook2 = Workbooks.Open("D:\Country&LocalReport\2022 - ECT - C&L - Personal.xlsm")
'Set oWorkbook1 = Workbooks.Open("D:\Country&LocalReport\RLE_County Local 2022.xls")
'Set oWorkbook2 = Workbooks.Open("D:\Country&LocalReport\Occ County Local 2022.xls")
Set oWorkbook1 = Workbooks.Open(sRLFilePath)
Set oWorkbook2 = Workbooks.Open(sCLFilePath)
'**************were on recipt leger it starts
iReportRowIndex1 = 4
iReportRowIndex2 = 4
'dRLMaxRows = CDbl(txtRLMaxRows.Value)
'dCLMaxRows = CDbl(txtCLMaxRows.Value)
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
.Interactive = False
End With
Do While dtCheckDate <= dtToDate
strSearchDate = Month(dtCheckDate) & "/" & Day(dtCheckDate) & "/" & Year(dtCheckDate)
iReportRowIndex1 = ProcessReportData("RL", strSearchDate, oWorkbook1, oReportWorkbook, iReportRowIndex1)
iReportRowIndex2 = ProcessReportData("CL", strSearchDate, oWorkbook2, oReportWorkbook, iReportRowIndex2)
'iReportRowIndex1 = ProcessReportData("RL", strSearchDate, oWorkbook1, oReportWorkbook, iReportRowIndex1, dRLMaxRows)
'iReportRowIndex2 = ProcessReportData("CL", strSearchDate, oWorkbook2, oReportWorkbook, iReportRowIndex2, dCLMaxRows)
'Call ProcessReportData2(strSearchDate, oWorkbook2)
dtCheckDate = DateAdd("d", 1, dtCheckDate)
Loop
With Application
CalcMode = .Calculation
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
.EnableEvents = True
.Interactive = True
End With
Call oWorkbook1.Close(False)
Call oWorkbook2.Close(False)
Call oReportWorksheet.Activate
lblMessage.BackColor = ColorConstants.vbGreen
lblMessage.Caption = "Completed with report generation !!!"
'Me.ActiveControl
'Unload Me
Exit Sub
ErrorHandler:
MsgBox "(GenerateReport) Something went wrong '" & Error() & "' at line " & Erl() & ", halting process!!!"
'Me.ActiveControl
lblMessage.BackColor = ColorConstants.vbGreen
lblMessage.Caption = "(GenerateReport) Something went wrong '" & Error() & "' at line " & Erl() & ", halting process!!!"
With Application
CalcMode = .Calculation
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
.EnableEvents = True
.Interactive = True
End With
If Not oWorkbook1 Is Nothing Then Call oWorkbook1.Close(False)
If Not oWorkbook2 Is Nothing Then Call oWorkbook2.Close(False)
Call oReportWorksheet.Activate
'Unload Me
Exit Sub
End Sub
Private Sub btnGenerate_Click()
'On Error GoTo ErrorHandler
lblMessage.BackColor = ColorConstants.vbGreen
lblMessage.Caption = "Now, generating the report !!!"
Dim strFromDate As String
Dim strToDate As String
Dim aFromDate As Variant
Dim aToDate As Variant
Dim dtFromDate As Date
Dim dtToDate As Date
Dim dtCheckDate As Date
Dim sRLFilePath As String
Dim sCLFilePath As String
'Dim dRLMaxRows As Double
'Dim dCLMaxRows As Double
Dim strSearchDate As String
Dim oReportWorkbook As Workbook
Dim oReportWorksheet As Worksheet
Dim oWorkbook1 As Workbook
Dim oWorkbook2 As Workbook
Dim iReportRowIndex1 As Double
Dim iReportRowIndex2 As Double
strFromDate = txtFromDate.Value
strToDate = txtToDate.Value
aFromDate = Split(strFromDate, "/")
aToDate = Split(strToDate, "/")
dtFromDate = DateSerial(aFromDate(2), aFromDate(0), aFromDate(1))
dtToDate = DateSerial(aToDate(2), aToDate(0), aToDate(1))
dtCheckDate = dtFromDate
sRLFilePath = txtRLFilePath.Value
sCLFilePath = txtCLFilePath.Value
Application.Interactive = False
Set oReportWorkbook = ActiveWorkbook
Set oReportWorksheet = ActiveSheet
'Set oWorkbook1 = Workbooks.Open("D:\Country&LocalReport\2022 - ECT - Real Estate.xlsx")
'Set oWorkbook2 = Workbooks.Open("D:\Country&LocalReport\2022 - ECT - C&L - Personal.xlsm")
'Set oWorkbook1 = Workbooks.Open("D:\Country&LocalReport\RLE_County Local 2022.xls")
'Set oWorkbook2 = Workbooks.Open("D:\Country&LocalReport\Occ County Local 2022.xls")
Set oWorkbook1 = Workbooks.Open(sRLFilePath)
Set oWorkbook2 = Workbooks.Open(sCLFilePath)
'**************were on recipt leger it starts
iReportRowIndex1 = 4
iReportRowIndex2 = 4
'dRLMaxRows = CDbl(txtRLMaxRows.Value)
'dCLMaxRows = CDbl(txtCLMaxRows.Value)
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
.EnableEvents = False
.Interactive = False
End With
Do While dtCheckDate <= dtToDate
strSearchDate = Month(dtCheckDate) & "/" & Day(dtCheckDate) & "/" & Year(dtCheckDate)
iReportRowIndex1 = ProcessReportData("RL", strSearchDate, oWorkbook1, oReportWorkbook, iReportRowIndex1)
iReportRowIndex2 = ProcessReportData("CL", strSearchDate, oWorkbook2, oReportWorkbook, iReportRowIndex2)
'iReportRowIndex1 = ProcessReportData("RL", strSearchDate, oWorkbook1, oReportWorkbook, iReportRowIndex1, dRLMaxRows)
'iReportRowIndex2 = ProcessReportData("CL", strSearchDate, oWorkbook2, oReportWorkbook, iReportRowIndex2, dCLMaxRows)
'Call ProcessReportData2(strSearchDate, oWorkbook2)
dtCheckDate = DateAdd("d", 1, dtCheckDate)
Loop
With Application
CalcMode = .Calculation
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
.EnableEvents = True
.Interactive = True
End With
Call oWorkbook1.Close(False)
Call oWorkbook2.Close(False)
Call oReportWorksheet.Activate
lblMessage.BackColor = ColorConstants.vbGreen
lblMessage.Caption = "Completed with report generation !!!"
'Me.ActiveControl
'Unload Me
Exit Sub
ErrorHandler:
MsgBox "(GenerateReport) Something went wrong '" & Error() & "' at line " & Erl() & ", halting process!!!"
'Me.ActiveControl
lblMessage.BackColor = ColorConstants.vbGreen
lblMessage.Caption = "(GenerateReport) Something went wrong '" & Error() & "' at line " & Erl() & ", halting process!!!"
With Application
CalcMode = .Calculation
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
.EnableEvents = True
.Interactive = True
End With
If Not oWorkbook1 Is Nothing Then Call oWorkbook1.Close(False)
If Not oWorkbook2 Is Nothing Then Call oWorkbook2.Close(False)
Call oReportWorksheet.Activate
'Unload Me
Exit Sub
End Sub