I'm doing the basic version of what I'm trying to achieve already through this code. Here I specify the date I want to start and finish looking. Now I'm just going to look through all the days and not specify how many month symbols I am looking at. So it will either be 2 or 3.
I coded it up as below and thought and array to store the data and use later would be an improvement rather then outputting into a sheet and then working with the data.
'This goes through the columns of data to find the specified symbol for month one. If that is present it will look for month2 and so on until
'all month columns are found.
Do Until Month1 = DataSheet.Cells(2, ColCountM1)
ColCountM1 = ColCountM1 + 5
FindEndCol = DataSheet.Cells(2, ColCountM1)
Loop
If Month2 <> Empty Then
Do Until Month2 = DataSheet.Cells(2, ColCountM2)
ColCountM2 = ColCountM2 + 5
Loop
If Month3 <> Empty Then
Do Until Month3 = DataSheet.Cells(2, ColCountM3)
ColCountM3 = ColCountM3 + 5
Loop
If Month4 <> Empty Then
Do Until Month4 = DataSheet.Cells(2, ColCountM4)
ColCountM4 = ColCountM4 + 5
Loop
End If
End If
End If
'This will work down the column for each month to find the closest date point to the start date.
Do Until DataSheet.Cells(RowCountM1, ColCountM1 + 3) > StartTime
RowCountM1 = RowCountM1 + 1
CurrDate = DataSheet.Cells(RowCountM1, ColCountM1 + 3)
Loop
If Month2 <> Empty Then
Do Until DataSheet.Cells(RowCountM2, ColCountM2 + 3) > StartTime
RowCountM2 = RowCountM2 + 1
CurrDate = DataSheet.Cells(RowCountM2, ColCountM2 + 3)
Loop
If Month3 <> Empty Then
Do Until DataSheet.Cells(RowCountM3, ColCountM3 + 3) > StartTime
RowCountM3 = RowCountM3 + 1
CurrDate = DataSheet.Cells(RowCountM3, ColCountM3 + 3)
Loop
If Month4 <> Empty Then
Do Until DataSheet.Cells(RowCountM4, ColCountM4 + 3) > StartTime
RowCountM4 = RowCountM4 + 1
CurrDate = DataSheet.Cells(RowCountM4, ColCountM4 + 3)
Loop
End If
End If
End If
'I'm looking to find how many data points I have between start and end times. So I use the cell which is the first cell from
'the start time to count from then loop till i get the end data point. Then I will know how many times to loop the following procedure
'because the first month symbol is the proxy for the rest.
EnDateCountM1 = RowCountM1
Do
EnDateCountM1 = EnDateCountM1 + 1
CurrDate = DataSheet.Cells(EnDateCountM1, ColCountM1 + 3)
Loop While DataSheet.Cells(EnDateCountM1, ColCountM1 + 3) < EndTime
i = 1 + EnDateCountM1 - RowCountM1
'Here I will use the first date in the range I'm looking at and try and find the corresponding one in each other month symbol.
'if it can't find it for that month then I just move and check for the next day. If it is present I do a little cal and store it.
For n = 1 To i
If Month1 <> Empty Then
StratPrice = 0
FutValueM1 = DataSheet.Cells(RowCountM1, ColCountM1 + 4)
ResultsSheet.Cells(1 + n, 1) = DataSheet.Cells(RowCountM1, ColCountM1 + 3)
ResultsSheet.Cells(1 + n, 2) = FutValueM1
StratPrice = (InputSheet.Cells(7, 3) * FutValueM1)
If Month2 <> Empty Then
If DataSheet.Cells(RowCountM2, ColCountM2 + 3) < DataSheet.Cells(RowCountM1, ColCountM1 + 3) Then
Do Until DataSheet.Cells(RowCountM2, ColCountM2 + 3) > DataSheet.Cells(RowCountM1, ColCountM1 + 3)
RowCountM2 = RowCountM2 + 1
Loop
Else
End If
FutValueM2 = DataSheet.Cells(RowCountM2, ColCountM2 + 4)
If DataSheet.Cells(RowCountM2, ColCountM2 + 3) = DataSheet.Cells(RowCountM1, ColCountM1 + 3) Then
ResultsSheet.Cells(1 + n, 3) = DataSheet.Cells(RowCountM1, ColCountM1 + 3)
ResultsSheet.Cells(1 + n, 4) = FutValueM2
RowCountM2 = RowCountM2 + 1
StratPrice = StratPrice + (InputSheet.Cells(7, 4) * FutValueM2)
If Month3 <> Empty Then
If DataSheet.Cells(RowCountM3, ColCountM3 + 3) < DataSheet.Cells(RowCountM1, ColCountM1 + 3) Then
Do Until DataSheet.Cells(RowCountM3, ColCountM3 + 3) > DataSheet.Cells(RowCountM1, ColCountM1 + 3)
RowCountM3 = RowCountM3 + 1
Loop
Else
End If
FutValueM3 = DataSheet.Cells(RowCountM3, ColCountM3 + 4)
If DataSheet.Cells(RowCountM3, ColCountM3 + 3) = DataSheet.Cells(RowCountM1, ColCountM1 + 3) Then
ResultsSheet.Cells(1 + n, 5) = DataSheet.Cells(RowCountM1, ColCountM1 + 3)
ResultsSheet.Cells(1 + n, 6) = FutValueM3
RowCountM3 = RowCountM3 + 1
StratPrice = StratPrice + (InputSheet.Cells(7, 5) * FutValueM3)
If Month4 <> Empty Then
If DataSheet.Cells(RowCountM4, ColCountM4 + 3) < DataSheet.Cells(RowCountM1, ColCountM1 + 3) Then
Do Until DataSheet.Cells(RowCountM4, ColCountM4 + 3) > DataSheet.Cells(RowCountM1, ColCountM1 + 3)
RowCountM4 = RowCountM4 + 1
Loop
Else
End If
FutValueM4 = DataSheet.Cells(RowCountM4, ColCountM4 + 4)
If DataSheet.Cells(RowCountM4, ColCountM4 + 3) = DataSheet.Cells(RowCountM1, ColCountM1 + 3) Then
ResultsSheet.Cells(1 + n, 7) = DataSheet.Cells(RowCountM1, ColCountM1 + 3)
ResultsSheet.Cells(1 + n, 8) = FutValueM4
RowCountM4 = RowCountM4 + 1
StratPrice = StratPrice + (InputSheet.Cells(7, 6) * FutValueM4)
End If
End If
End If
End If
End If
End If
ResultsSheet.Cells(1 + n, 10) = DataSheet.Cells(RowCountM1, ColCountM1 + 3)
ResultsSheet.Cells(1 + n, 11) = StratPrice
RowCountM1 = RowCountM1 + 1
End If
Next n