Bonjour,

J'ai commencé un peu le travail, le code tourne mais ne réalise pas ce que je veux. La macro à pour but d'extraire des données contenues dans un fichier csv et de les copier sur une feuille de mon classeur appelée "reception_donnees". Je n'arrive pas à "coller" les données receuillies à partir du fichier csv sur ma feuille "reception_donnees" et pourtant ma fonction s'exécute sans problème.
Si quelqu'un peut me dire comment puis-je récupérer les données que je parcours ça serais bien sympas.

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
 
Public Sub LireCSV(ByVal Chemin As String, col1 As Integer, col2 As Integer, col3 As Integer, col4 As Integer, col5 As Integer)
Dim Chaine As String
Dim Ar() As String
Dim i As Long
Dim iRow As Long, iCol As Long
Dim NumFichier As Integer
Dim Separateur As String * 1
 
    Sheets("reception_donnees" ).Activate
    Separateur = ";"
    Cells.Clear
    Application.ScreenUpdating = False
    NumFichier = FreeFile
 
    iRow = 0
    Open Chemin For Input As #NumFichier
    Do While Not EOF(NumFichier)
        iCol = 1
        iRow = iRow + 1
        Line Input #NumFichier, Chaine
        Ar = Split(Chaine, Separateur)
 
       For i = LBound(Ar) To UBound(Ar)
           If (i = col1 Or i = col2 Or i = col3 Or i = col4 Or i = col5) Then
             Cells(iRow, iCol) = Ar(i)
              iCol = iCol + 1
           End If
        Next i
 
    Loop
    Close #NumFichier
    Application.ScreenUpdating = True
    MsgBox "Le fichier à bien été importé !", vbInformation, "Importation de données"
 
End Sub