Public Sub initialisation()
' Sauvegarde et initialisation tableau
Dim col As Integer
Dim del As Long
Dim der As Long
Dim top As Long
Dim nom As String
Dim rep As String
nom = Left(ThisWorkbook.FullName, InStrRev(ThisWorkbook.FullName, "\")) & "sav_" & ThisWorkbook.Name
If MsgBox("Voulez-vous sauvegarder ce document ?", vbYesNo, "Confirmation sauvegarde") = vbYes Then
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Choisissez le répertoire de sauvegarde"
.InitialFileName = nom
If .Show = -1 Then
rep = .SelectedItems(1)
nom = InputBox("Saisissez votre nom de sauvegarde", " NOM DE SAUVEGARDE", Mid(nom, InStrRev(ThisWorkbook.FullName, "\") + 1))
ThisWorkbook.SaveCopyAs rep & "\" & nom
MsgBox "Classeur sauvegardé"
Else
MsgBox "Classeur non sauvegardé"
End
End If
End With
End If
If MsgBox("Voulez-vous initialiser ce document ?", vbYesNo, "Confirmation initialisation") = vbYes Then
Set ws = ThisWorkbook.Worksheets("Facture")
ws.Activate
With ws.ListObjects("FactureSimple")
top = .HeaderRowRange.Row
der = .ListRows.Count
For col = 1 To .ListColumns.Count
If Left(.DataBodyRange.Item(1, col).Formula, 1) <> "=" Then
.DataBodyRange.Item(1, col).Value = ""
End If
Next col
End With
For del = ws.Cells(Rows.Count, "Q").End(xlUp).Row To top + der + 2 Step -1
If Left(ws.Cells(del, "Q").Formula, 1) <> "=" Then
ws.Cells(del, "N").Resize(1, 4).Value = ""
End If
Next del
ws.Range("C2").Value = ""
ws.Range("C3").Value = ""
'---------------- modifications ici
With ws.ListObjects("FactureSimple")
.DataBodyRange.Delete
End With
' ---------------- fin des modifications
End If
ActiveWindow.ScrollRow = 1
End Sub