Erreur et mauvaise organisation du code

TraderAS Messages postés 110 Date d'inscription   Statut Membre Dernière intervention   -  
TraderAS Messages postés 110 Date d'inscription   Statut Membre Dernière intervention   -
bonjour,

je suis débutant avec VBA/Excel j'ai écris ce code mais je ne sais pas comment l'organiser
en faite je veux ouvrir un fichier, insérer une ligne, incrémenter la cellule de la colonne A, et fair un copier coller d'un ActiveWorkbook.Name

voici ce code:

Sub CopierColler()
Application.ScreenUpdating = False
Rep = "C:\Users\toshiba\Desktop\TRADING\Historical\"
FichD = ActiveWorkbook.Name
FichS = "Adwya.xlsm"

Sub test()
Workbooks.Open Rep & FichS
Rows("5:5").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
[A5] = [A6] + 1
End Sub

With Workbooks(FichD)
.Sheets("Fundamentals").Range("C5:G5").Copy _
Workbooks(FichS).Sheets("Feuil1").Range("C9:F9").End(xlUp).Offset(1, 0)
Workbooks(FichS).Save
Workbooks(FichS).Close
End With

End Sub

merci
A voir également:

2 réponses

pilas31 Messages postés 1825 Date d'inscription   Statut Contributeur Dernière intervention   646
 
Bonjour,

A priori le problème vient du fait qu'il y a la macro "test" qui est imbriquée dans la macro "CopierColler".

Dans un premier temps, il faut essayer comme ceci :

Sub CopierColler()  
Application.ScreenUpdating = False  
Rep = "C:\Users\toshiba\Desktop\TRADING\Historical\"  
FichD = ActiveWorkbook.Name  
FichS = "Adwya.xlsm"  

Workbooks.Open Rep & FichS  
Rows("5:5").Select  
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove  
[A5] = [A6] + 1  

With Workbooks(FichD)  
.Sheets("Fundamentals").Range("C5:G5").Copy _  
Workbooks(FichS).Sheets("Feuil1").Range("C9:F9").End(xlUp).Offset(1, 0)  
Workbooks(FichS).Save  
Workbooks(FichS).Close  
End With  
Application.ScreenUpdating = True  
End Sub  



Nous dire si le fonctionnement est correct

A+
Cordialement,
0
TraderAS Messages postés 110 Date d'inscription   Statut Membre Dernière intervention   1
 
ca marche, pilas31, merci pour votre précieuse aide
Tradre AS
0