Hi
Windows 7 Excel 2010
what iam trying to do is
in A2 User Input Date "1-Sep-2015"
This Formula in B2 =FSGetDates(A2,B1) Function Return Should be "02-Sep-2015 06:01:10" first it should check Cycle Date if match user input Compare Dates To The right of Execution Date Time then Get earliest
This Formula in C2 =FSGetDAtes(A2,C1) Function Return Should be "02-Sep-2015 06:03:56" first it should check Cycle Date if match user input Compare Dates To The right of Completed at then Get recent
here is my code
sample Data
my code return #VALUE!
Thanks
Windows 7 Excel 2010
what iam trying to do is
in A2 User Input Date "1-Sep-2015"
This Formula in B2 =FSGetDates(A2,B1) Function Return Should be "02-Sep-2015 06:01:10" first it should check Cycle Date if match user input Compare Dates To The right of Execution Date Time then Get earliest
This Formula in C2 =FSGetDAtes(A2,C1) Function Return Should be "02-Sep-2015 06:03:56" first it should check Cycle Date if match user input Compare Dates To The right of Completed at then Get recent
here is my code
Code:
Function FSGetDates(DateStr As String, ReturnType As String) As Date Dim myfile As String
Dim FileName As String
Dim TempDate As String
folderName = Cells(2, 11).Value
i = 1
myfile = Dir(folderName & "\" & "*.txt")
Do While myfile <> ""
Open folderName & "\" & myfile For Input Access Read As #1
While Not EOF(1)
Line Input #1, EntireLine
If InStr(1, EntireLine, "Execution Date Time:") > 0 And InStr(1, EntireLine, DateStr) > 0 Then
Select Case LCase(ReturnType)
Case Is = "start"
If IsDate(Trim(Right(EntireLine, InStr(1, EntireLine, "Execution Date Time:") - 1))) And TempDate = "" Then
TempDate = Trim(Right(EntireLine, InStr(1, EntireLine, "Execution Date Time:") - 1))
ElseIf StartDate <> "" And Trim(Right(EntireLine, InStr(1, EntireLine, "Execution Date Time:") - 1)) < TempDate Then
TempDate = Trim(Right(EntireLine, InStr(1, EntireLine, "Execution Date Time:") - 1))
End If
Case Is = "end"
If IsDate(Trim(Right(EntireLine, InStr(1, EntireLine, "Completed at:") - 1))) And TempDate = "" Then
TempDate = Trim(Right(EntireLine, InStr(1, EntireLine, "Completed at:") - 1))
ElseIf TempDate <> "" And Trim(Right(EntireLine, InStr(1, EntireLine, "Completed at:") - 1)) > TempDate Then
TempDate = Trim(Right(EntireLine, InStr(1, EntireLine, "Completed at:") - 1))
End If
End Select
End If
Wend
Close #1
myfile = Dir
Loop
FSGetDates = DateValue(TempDate) + TimeValue(TempDate)
End Function
sample Data
Code:
======================================== Execution Date Time:02-Sep-2015 06:01:10 AM ========================================
------------------------- Cycle Date 01-Sep-2015 Product Z2 -------------------
xx:[xxxxx xxxxx] 0
xx:[xxxxx xxx xxxx] 0
xx:[xxx xxxx] 17
From Data 17
xxxxxx x 0
xxx xxxxxx 6
xxxx xx x 4
xxxxxx x 7
xxxxxx xxxxx x 7
------------------------------------------------------------------------------ Completed at: 02-Sep-2015 06:02:56 AM --------------------------------------- -----------------------------
======================================== Execution Date Time:02-Sep-2015 06:03:10 AM ========================================
------------------------- Cycle Date 01-Sep-2015 Product Z1 -------------------
xx:[xxxxx xxxx] 0
xx:[xxxxx xxx xxxx] 0
xx:[xxx xxxx] 18
From Data 18
xxxxxx x 0
xxx xxxxxx 6
xxxx xx x 4
xxxxxx x 7
xxxxxx xxxxx x 7
------------------------------------------------------------------------------ Completed at: 02-Sep-2015 06:03:56 AM --------------------------------------------------------------------
my code return #VALUE!
Thanks