Range(cells)

Bonjour, Je souhaite copier les données de plusieurs fichiers (présents dans un autre dossier) dans une feuille d'un autre fichier "Tamplate" qui me permettrait de tout avoir sous les yeux. il faudrait que je copie la colonne C1:C113 de tout les fichier dans une autre colonne de mon fichier "Tamplate". La colone de direction doit s'incrémenté avec une boucle pour que chacune se copie à la suite.

Le reste de moncode marche parfaitement, cependant, cette ligne ne marche pas : ThisWorkbook.Worksheets(2).Range(Cells(1, intCurrentCol), Cells(113, intCurrentCol)).Value = WbCurrent.Sheets(1).Range("C1:C113").Value

Excel me dit "erreur défini par l'application ou par l'objet"

Si quelqu'un pourrais m'aider ce serai super je vous remercie par avance

Voici le code entier avec mes commentaires (en anglais) :

Sub importData()

Const BASE_DIRECTORY = "Data Shop"

Dim strPath As String

Dim strFileName As String

Dim WbCurrent As Workbook

Dim intCurrentCol As Integer: intCurrentCol = 3

strPath = ThisWorkbook.Path & Application.PathSeparator & BASE_DIRECTORY & Application.PathSeparator

'MsgBox (strPath)

strFileName = Dir(strPath)'Retrieving the name of the first file of the test Directory

'MsgBox (strFileName)

Do Until strFileName = "" 'Do this util we do not have more files

Set WbCurrent = Application.Workbooks.Open(strPath & strFileName)

ThisWorkbook.Worksheets(2).Range(Cells(1, intCurrentCol), Cells(113, intCurrentCol)).Value = WbCurrent.Sheets(1).Range("C1:C113").Value

intCurrentCol = intCurrentCol + 1

WbCurrent.Close

strFileName = Dir() 'Retrieving the next file name

Loop 'end of the loop

End Sub

Bonjour,

Essaie ainsi :

Sub importData()
Const BASE_DIRECTORY = "\Data Shop\"
Const N As Long = 113
Dim WbCurrent As Workbook, Wb As Workbook
Dim strPath As String, strFileName As String
Dim intCurrentCol As Integer
    Set WbCurrent = ThisWorkbook
    strPath = WbCurrent.Path & BASE_DIRECTORY
    strFileName = Dir(strPath & "*.xls")
    intCurrentCol = 3
    Do Until strFileName = ""
        Set Wb = Application.Workbooks.Open(strPath & strFileName)
        WbCurrent.Worksheets(2).Cells(1, intCurrentCol).Resize(N).Value _
                = Wb.Worksheets(1).Cells(3).Resize(N).Value
        intCurrentCol = intCurrentCol + 1
        Wb.Close savechanges:=False
        strFileName = Dir()
    Loop
End Sub

Whaaouu super merci, en plus tu m'as simplifié mon code

Juste une question, ça sert à quoi le .Resize ? J'ai envie de comprendre comme ça je ne demanderais pas d'aide pour le même problème ^^

Rechercher des sujets similaires à "range"