Copier N lignes sous excel

ccoste Messages postés 1 Date d'inscription   Statut Membre Dernière intervention   -  
Polux31 Messages postés 6917 Date d'inscription   Statut Membre Dernière intervention   -
Je souhaite copier N lignes d'un fichier source vers un fichier cible. Ci-dessous la macro faite mais elle ne marche pas. Pouvez vous trouver l'erreur?

Sub Liste()

Dim strMessage As String
Dim i As Long

Dim ligne As Integer
Dim lignestr As String
Dim lignestrsource As String
Dim Datacible As String
Dim Datasource As String
Dim nomfichiersource As String
Dim nomfichiercible As String


moncheminsource = [Feuil1!B3]
monchemincible = [Feuil1!B5]

'Si tes classeurs sont fermés

'fichier source = rapport BBH
Set Wbk1 = Workbooks.Open(Filename:=moncheminsource)
nomfichiersource = ActiveWorkbook.Name

'On compte le nombre de ligne dans le fichier source
Dim S As Double
Dim j As Double
For j = 1 To Cells(65536, 2).End(xlUp).Row
If Not Rows(j).Hidden Then S = S + 1
Next j

'On convertit le nombre de ligne du fichier cible en string et on supprime tous les blancs
lignestrsource = Str(S + 1)
lignestrsource = Trim$(lignestrsource)

Datasource1 = "A" & lignestrsource
Datasource2 = "B" & lignestrsource
Datasource3 = "C" & lignestrsource
Datasource4 = "D" & lignestrsource
Datasource5 = "E" & lignestrsource
Datasource6 = "F" & lignestrsource
Datasource7 = "G" & lignestrsource
Datasource8 = "H" & lignestrsource
Datasource9 = "I" & lignestrsource
Datasource10 = "J" & lignestrsource
Datasource11 = "K" & lignestrsource
Datasource12 = "L" & lignestrsource

'fichier cible = fichier Historique_Sweep_Report_BBH
Set Wbk2 = Workbooks.Open(Filename:=monchemincible)
nomfichiercible = ActiveWorkbook.Name
Workbooks(nomfichiercible).Sheets("Histo").Activate

'On compte le nombre de ligne dans le fichier cible
Dim R As Double
Dim l As Double
For l = 1 To Cells(65536, 2).End(xlUp).Row
If Not Rows(l).Hidden Then R = R + 1
Next l

'On convertit le nombre de ligne du fichier cible en string et on supprime tous les blancs
lignestr = Str(R + 1)
lignestr = Trim$(lignestr)

Datacible1 = "A" & lignestr
Datacible2 = "B" & lignestr
Datacible3 = "C" & lignestr
Datacible4 = "D" & lignestr
Datacible5 = "E" & lignestr
Datacible6 = "F" & lignestr
Datacible7 = "G" & lignestr
Datacible8 = "H" & lignestr
Datacible9 = "I" & lignestr
Datacible10 = "J" & lignestr
Datacible11 = "K" & lignestr
Datacible12 = "L" & lignestr



'On copie les données dans l'onglet Histo

'### pour prendre la date du rapport BBH - Sweep out date
Workbooks(nomfichiercible).Sheets("Histo").Range(Datacible1) = Workbooks(nomfichiersource).Sheets("CMSAllocations").Range(Datasource1)

'### pour prendre la date du rapport BBH - Sweep Return date
Workbooks(nomfichiercible).Sheets("Histo").Range(Datacible2) = Workbooks(nomfichiersource).Sheets("CMSAllocations").Range(Datasource2)

'### pour la partie BBH Head Account
'N° de compte chez BBH
Workbooks(nomfichiercible).Sheets("Histo").Range(Datacible3) = Workbooks(nomfichiersource).Sheets("CMSAllocations").Range(Datasource3)


'Nom de compte chez BBH
Workbooks(nomfichiercible).Sheets("Histo").Range(Datacible4) = Workbooks(nomfichiersource).Sheets("CMSAllocations").Range(Datasource4)

'CCy du compte
Workbooks(nomfichiercible).Sheets("Histo").Range(Datacible5) = Workbooks(nomfichiersource).Sheets("CMSAllocations").Range(Datasource5)


'### pour la partie Sweep Bank(Parent)
Workbooks(nomfichiercible).Sheets("Histo").Range(Datacible6) = Workbooks(nomfichiersource).Sheets("CMSAllocations").Range(Datasource6)

'### pour la partie Sweep Bank(Branch)
Workbooks(nomfichiercible).Sheets("Histo").Range(Datacible7) = Workbooks(nomfichiersource).Sheets("CMSAllocations").Range(Datasource7)


'### Pour la partie Nb jours Int
Workbooks(nomfichiercible).Sheets("Histo").Range(Datacible8) = Workbooks(nomfichiersource).Sheets("CMSAllocations").Range(Datasource8)

'### Pour la partie Local Sweep Amt
Workbooks(nomfichiercible).Sheets("Histo").Range(Datacible9) = Workbooks(nomfichiersource).Sheets("CMSAllocations").Range(Datasource9)

'### Pour la partie USD Equiv Sweep Amt
Workbooks(nomfichiercible).Sheets("Histo").Range(Datacible10) = Workbooks(nomfichiersource).Sheets("CMSAllocations").Range(Datasource10)

'### Pour la partie Interest Rate
Workbooks(nomfichiercible).Sheets("Histo").Range(Datacible11) = Workbooks(nomfichiersource).Sheets("CMSAllocations").Range(Datasource11)

'### Pour la partie Local Interest Earned Amt
Workbooks(nomfichiercible).Sheets("Histo").Range(Datacible12) = Workbooks(nomfichiersource).Sheets("CMSAllocations").Range(Datasource12)


'On ferme le fichier source
Wbk1.Close

'ActiveWorkbook.Save

End Sub
A voir également:

1 réponse

Polux31 Messages postés 6917 Date d'inscription   Statut Membre Dernière intervention   1 204
 
Bonjour,

"Ci-dessous la macro faite mais elle ne marche pas."

Beaucoup trop vague comme indication pour donner un avis ...
0