1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
'Function builds a Array with the market data for the wanted product between the startDate and the endDate
'cdtyCurve = getCdtyCurve(product, startDate, EndDate)
Public Function getCdtyCurve(ByVal product As String, ByVal startdate As String, ByVal enddate As String) As Double()
Dim var() As Double
Dim mainsheet As Worksheet
Set mainsheet = ThisWorkbook.Sheets("MAIN")
Dim startDateString As String
'récupération de la colonne des données
mainsheet.Cells.Select
Selection.Find(What:=product, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
'on trouve d'abord le nom du product dans la barre de sélection puis notre colonne
Selection.FindNext(After:=ActiveCell).Activate
colonne = ActiveCell.Column
'récupération de la ligne startDate
Range(mainsheet.Cells(1, 1), mainsheet.Cells(5000, 5)).Select
Selection.Find(What:=startdate, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=True, SearchFormat:=True).Activate
'on trouve d'abord le sélecteur puis notre ligne
Selection.FindNext(After:=ActiveCell).Activate
lignestartdate = ActiveCell.Row
'récupération de la ligne endDate
Range(Cells(1, 1), Cells(5000, 5)).Select
Selection.Find(What:=enddate, After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=True, SearchFormat:=True).Activate
'on trouve d'abord le sélecteur puis notre ligne
Selection.FindNext(After:=ActiveCell).Activate
ligneenddate = ActiveCell.Row
mainsheet.Cells(1, 1).Select
'redimentionne le variant
taille = ligneenddate - lignestartdate + 1
ReDim var(taille)
'on remplit le variant
For i = 1 To taille
var(i) = mainsheet.Cells(i + lignestartdate - 1, colonne).Value
Next i
getCdtyCurve = var
'test de la fonction
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Feuil1")
ws.Cells(1, 10) = "getCdtyCurve"
For i = 1 To UBound(var)
ws.Cells(i + 1, 10) = var(i)
Next i
End Function |
Partager