Bonjour

J essaie de faire une fonction sour VBA qui recopie des cellules suivant une condition, et je ne comprend pas le bug ( sous Excel OSX , tres peu de commande de debugage), Je suis debutant en VBa et je ne comprend pas ou est mon erreur..
Est ce que quelqu un pourrait relire mon code et me dire ce qui ne va pas , svp ?

merci
--SSM

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
Public Function ReportDateSelection(rgA, rgB, sDate, eDate) As Variant
 
    Dim result() As Integer
    Dim cnt As Integer
    Dim n As Integer
    Dim CallerColumn As Integer
    Dim CallerRow As Integer
 
    'first Cell where you want to insert the
    Dim resultCell As Range
 
 
    cnt = 0
    For n = 1 To rgA.Rows.Count
        If (rgA.Cells(n, 1).Value >= sDate) And (rgA.Cells(n, 1).Value <= eDate) Then
            cnt = cnt + 1
            ReDim Preserve result(1 To cnt)
            result(cnt) = n
        End If
    Next
 
 
    CallerColumn = Range(Application.Caller.Address).Column
    CallerRow = Range(Application.Caller.Address).Row
    If (cnt > 0) Then
        If (cnt > 1) Then
            For i = 2 To cnt
                ActiveSheet.Cells(CallerRow + i -1, CallerColumn).Value = rgB(result(i)).Value
            Next i
        End If
 
        ReportDateSelection = rgB(result(1)).Value
CallerColumn).Value
    Else
        GoTo ErrorHandler
    End If
 
    Exit Function
 
ErrorHandler:
   MaxColumns = -1
End Function