Créer une nouvelle feuille excel grâce à un macro

Bonjour,

A tester

La macro

Sub Enregistrer()
  'Déclaration des variables
  Dim Dl%, Sh As Shape
  Dim Ws As Worksheet, Wd As Worksheet, NF As Worksheet
  'Initialisation des variables
  Set Ws = Sheets("FACTURES 00")
  Set Wd = Sheets("DETAIL")
  Dl = Wd.Range("B" & Rows.Count).End(xlUp).Row + 1 '1ère ligne vide pour DETAIL
    'Si le N° de Facture n'est pas renseigné, message et sortie de la macro
    If Ws.Cells(3, 7) = "" Then
      MsgBox " Vous n'avez pas renseigné le N° de Facture !", vbInformation, "Information"
      Exit Sub
    End If
    Wd.Cells(Dl, 2).Value = CDate(Ws.Cells(1, 9).Value) 'Date
    Wd.Cells(Dl, 3).Value = Ws.Cells(3, 7).Value        'N° Facture
    Wd.Cells(Dl, 4).Value = Ws.Cells(1, 2).Value        'Nom
    Wd.Cells(Dl, 5).Value = Ws.Cells(2, 2).Value        'Adresse
    Wd.Cells(Dl, 6).Value = Ws.Cells(3, 2).Value        'N° tél
    Wd.Cells(Dl, 7).Value = Ws.Cells(4, 2).Value        'N° IFU
    Wd.Cells(Dl, 8).Value = Ws.Cells(5, 2).Value        'N° Contrat
    Wd.Cells(Dl, 9).Value = Ws.Cells(16, 7).Value       'Total Qté
    Wd.Cells(Dl, 10).Value = Ws.Cells(16, 9).Value      'Montant HT
    Wd.Cells(Dl, 11).Value = Ws.Cells(17, 8).Value      'Taux AIB
    Wd.Cells(Dl, 12).Value = Ws.Cells(17, 9).Value      'Montant AIB
    'Wd.Cells(Dl, 13).Value = ??? Litre de Gasoil
    Wd.Cells(Dl, 14).Value = Ws.Cells(20, 9).Value      'Montant Gasoil
    Wd.Cells(Dl, 15).Value = Ws.Cells(21, 9).Value      'NAP
    'Ajout d'une feuille
    Ws.Copy After:=Sheets(Worksheets.Count)
    Set NF = ActiveSheet 'Initialisation Feuille
    With NF
       .Name = Ws.Range("G3") 'Renommer la feuille avec N° Facture
    End With
    For Each Sh In NF.Shapes  'Suppression du bouton
      Sh.Delete
    Next Sh
    Ws.Activate 'Activation feuille FACTURE 00
    Ws.Range("B1:B5,G3,G16,A13:D15,F13:G15,G18:H19") = "" 'Vide ancienne données
    Ws.Range("G3").Select 'Se positionne sur N° Facture
End Sub

facture.xlsm (101,7 Ko)