Re !
L'exemple que je vous avais mis était pour finalité l'adapter à une macro qui doit imiter une fonction de bloomberg mais j'ai du mal à l'appliquer
Pourriez vous y jeter un œil ?
Il y a une discussion ouverte à ce propos avec toutes les explications! Une fonction avec comment argument ticker -> fichier à interroger durant un intervalle de date
https://forum.excel-pratique.com/excel/fonction-qui-recupere-des-donnees-filtres-et-sort-un-tableau-...
Mais l'idée je veux faire comme la fonction précédente !
Function histo(ticker As String, date1 As String, date2 As String)
Evaluate "getdata1(" & Application.Caller.Offset(0, 1).Address(False, False) & ticker & "," & date1 & "," & date2 & ")"
histo = "matrice >>"
End Function
Private Sub getdata1(CellToChange As Range, ticker As String, Datedebut As String, Datefin As String) '''
Application.ScreenUpdating = False
Dim FilePath As String
Dim wbTicker As Workbook
Dim wsTicker As Worksheet
Dim datas() As Variant
FilePath = "C:\" & ticker & ".xlsx"
If FichierExiste(FilePath) = False Then
MsgBox "Le fichier " & ticker & " n'existe pas dans la base, veuillez le créer!"
Exit Sub
Else:
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
On Error Resume Next
Set Rng = .AutoFilter.Range.Cells.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If Not Rng Is Nothing Then
With wbTicker.Worksheets.Add
Rng.Copy .Range("A1")
datas = .UsedRange.Value
Application.DisplayAlerts = False
.Delete
Application.DisplayAlerts = True
End With
CellToChange.Resize(UBound(datas, 1), UBound(datas, 2)) = datas
Else
MsgBox "Filtre sans résultat"
End If
wbTicker.Close SaveChanges:=False
End If
Application.ScreenUpdating = True
Set wbTicker = Nothing: Set wsTicker = Nothing:
End Sub
Merci!!
Lucy