Option Explicit
Private Sub Numero_Fattura()
Dim ws1 As Worksheet: Set ws1 = Sheets("Fatturazione")
'Dim ws2 As Worksheet: Set ws2 = Sheets("Archivio")'se lo desideri fare
Dim Uriga As Long, Risposta As Integer
'ActiveSheet.Unprotect
Uriga = ws1.Range("BW" & Rows.Count).End(xlUp).Row ' ricerco l'ultima riga scritta
ws1.Range("M3").Value = ws1.Range("BW" & Uriga) + 1 ' Trovo l'ultima fattura e aggiungo +1 e la scrivo in M3
'Meglio fare delle verifiche prima sui dati importanti ex
If ws1.Range("D13") = "" Then MsgBox "Manca il cognome"
If ws1.Range("E13") = "" Then MsgBox "Manca la data"
If ws1.Range("F13") = "" Then MsgBox "Manca l'indirizzo"
If ws1.Range("G13") = "" Then MsgBox "Manca ecc ecc"
If ws1.Range("H13") = "" Then MsgBox "Manca ecc ecc"
Risposta = MsgBox(prompt:="Devo archiviare la fattura?", Buttons:=vbYesNo)
If Risposta = vbYes Then
'MsgBox "hai premuto si" ' archivio
ws1.Range("BW" & Uriga + 1) = ws1.Range("M3")
ws1.Range("D13:H13").Copy
ws1.Range("BX" & Uriga + 1).PasteSpecial
'continua Tu con il copiare i dati, alla fine svuoti la fattura
'Sheets("Fatturazione").Range("D13:H13,M13:M16,C19:K35,D39:F43,J42:M44,C46:M49").ClearContents
'Sheets("Fatturazione").Range("M13").ClearContents
Else
'MsgBox "hai premuto no" 'esco senza fare nulla
' se vuoi puoi cancellare tutti i dati dlla fattura
'Sheets("Fatturazione").Range("D13:H13,M13:M16,C19:K35,D39:F43,J42:M44,C46:M49").ClearContents
End If
Sheets("Fatturazione").Range("D13").Select
'ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Set ws1 = Nothing
'Set ws2 = Nothing
End Sub |