XL 2019 L'indice n'appartient pas à la sélection

  • Initiateur de la discussion Initiateur de la discussion Afro
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Afro

XLDnaute Nouveau
Bonjour j'aimerais que vous m'aidiez à débugué mon code :
Sub SauvegarderFacture()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim cheminwk2 As String
Range("Invoice").Value = Range("Facture").Value
'ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & "Facture" & "\" & Range("C7").Value & "-" & Range("C16").Value, FileFormat:=xlOpenXMLWorkbook
Set wb1 = ThisWorkbook
'Set wb2 = ActiveWorkbook
'cheminwk2 = ThisWorkbook.Path & "\" & "Sauvegarde" & ".xlsm"
cheminwk2 = "C:\Users\ThinkCentre\Desktop\Sauvegarde.xlsm"
Workbooks.Open cheminwk2
Set wb2 = ActiveWorkbook
wb1.Sheets("Invoice").Copy after:=wb2.Sheets(Sheets.Count)
activesheets.Name = ActiveSheet.Range("C8").Value & "-" & Year(ActiveSheet.Range("F5").Value)
End Sub
 
Solution
Bonjour,

Sub SauvegarderFacture()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim cheminwk2 As String
Dim invoiceSheet As Worksheet

' Copy data from "Facture" to "Invoice" sheet
Set invoiceSheet = ThisWorkbook.Sheets("Invoice")
invoiceSheet.Range("Facture").Value = invoiceSheet.Range("Invoice").Value

' Save current workbook path
Set wb1 = ThisWorkbook

' Open the destination workbook
cheminwk2 = "C:\Users\ThinkCentre\Desktop\Sauvegarde.xlsm"
Set wb2 = Workbooks.Open(cheminwk2)

' Copy the "Invoice" sheet to the destination workbook
invoiceSheet.Copy After:=wb2.Sheets(wb2.Sheets.Count)

' Rename the new sheet
With wb2.ActiveSheet
.Name =...
Bonjour,

Sub SauvegarderFacture()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim cheminwk2 As String
Dim invoiceSheet As Worksheet

' Copy data from "Facture" to "Invoice" sheet
Set invoiceSheet = ThisWorkbook.Sheets("Invoice")
invoiceSheet.Range("Facture").Value = invoiceSheet.Range("Invoice").Value

' Save current workbook path
Set wb1 = ThisWorkbook

' Open the destination workbook
cheminwk2 = "C:\Users\ThinkCentre\Desktop\Sauvegarde.xlsm"
Set wb2 = Workbooks.Open(cheminwk2)

' Copy the "Invoice" sheet to the destination workbook
invoiceSheet.Copy After:=wb2.Sheets(wb2.Sheets.Count)

' Rename the new sheet
With wb2.ActiveSheet
.Name = .Range("C8").Value & "-" & Year(.Range("F5").Value)
End With

' Save and close the destination workbook
wb2.Close SaveChanges:=True

' Reactivate the original workbook
wb1.Activate
End Sub
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
2
Affichages
422
Retour