helloo Franck!!
J'espère que çava! Je ne t'ai pas fais de retour immédiat désolé mais j'ai bien regardé les documents que tu m'as envoyé, je me suis entêtée dans ma fonction mais sans résultat, je me suis donc pencher sur les worksheets events et j'ai opté le worksheets change cela donne ceci !
Reminder fonction
Public Function donneeFuncFinale(ticker As String, Datedebut As String, Datefin As String) As Variant
Application.ScreenUpdating = False
Dim FilePath As String
Dim wbTicker As Workbook
Dim wsTicker As Worksheet
Dim Rng As Range
Dim datas()
Dim wb As Workbook, ws As Worksheet, wc As Range
Set wb = ActiveWorkbook
Set ws = ActiveSheet
Set wc = ActiveCell
FilePath = "C:\" & ticker & ".xlsx"
Set wbTicker = Workbooks.Open(FilePath)
Set wsTicker = wbTicker.Sheets("Feuil1")
With wsTicker
.AutoFilterMode = False
.Range("A2").AutoFilter Field:=1, Criteria1:=">=" & Format(Datedebut, "mm/dd/yyyy"), _
Operator:=xlAnd, Criteria2:="<=" & Format(Datefin, "mm/dd/yyyy"), VisibleDropDown:=False
Set Rng = .AutoFilter.Range.Cells.SpecialCells(xlCellTypeVisible)
End With
With wbTicker.Worksheets.Add
Rng.Copy .Range("A1")
datas = .UsedRange.Value
Application.DisplayAlerts = False
.Delete
Application.DisplayAlerts = True
End With
donneeFuncFinale = datas
wbTicker.Close SaveChanges:=False
Application.ScreenUpdating = True
Set wb = Nothing: Set ws = Nothing: Set wc = Nothing: Set wbTicker = Nothing: Set wsTicker = Nothing:
End Function
Ensuite, l’événement
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim datas As Variant
Dim ContenuInitial As String
Dim a() As String
Dim ticker As String, d1 As String, d2 As String
ContenuInitial = Target.Value
a() = Split(ContenuInitial, ";")
ticker = a(0)
d1 = a(1)
d2 = a(2)
datas = donneeFuncFinale(ticker, d1, d2)
Target.Resize(UBound(datas, 1), UBound(datas, 2)).Value = datas
Application.EnableEvents = True
End Sub
donc je rentre dans la cellule active -> ticker; dateDebut; dateFin et ça me sort le résulat ( du coup le tableau trié).
Mais je me retrouve face à plusieurs problématiques:
-adapter le code pour qu"ils puissent marcher sur n'importe quelle classeur et feuilles du coup, je pense donc utiliser une module de classe
- et faire en sorte d'utiliser le work sheet change plusieurs fois d'affilés car dans mon coté il ne fonctionne qu'une seule fois
Si vous avez des idées ou autres, je suis preneuse
Merci et bonne journée :)
Lucy