Untitled
unknown
vbscript
2 years ago
1.9 kB
8
Indexable
Sub ajouter_button()
Dim ws As Worksheet
Dim lastRow As Long
Dim nextEmptyRow As Long
Dim totalHTRow As Long
Dim tvaRow As Long
Dim totalTTCRow As Long
Set ws = ThisWorkbook.Sheets("Nom_de_votre_feuille") ' Remplacez "Nom_de_votre_feuille" par le nom de votre feuille
If Range("K8") = "" Or Range("K9") = "" Or Range("K10") = "" Or Range("K11") = "" Or Range("K12") = "" Then
MsgBox ("Des informations manquantes")
Else
' Recherche de la dernière ligne utilisée dans la colonne B
lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
' Trouver la prochaine ligne vide dans la colonne B
If lastRow < 10 Then
nextEmptyRow = 10
Else
nextEmptyRow = lastRow + 1
End If
' Vérifier si "Total HT", "TVA 20%" et "Total TTC" sont dans la colonne E et décaler si nécessaire
totalHTRow = Application.Match("Total HT", ws.Columns("E"), 0)
tvaRow = Application.Match("TVA 20%", ws.Columns("E"), 0)
totalTTCRow = Application.Match("Total TTC", ws.Columns("E"), 0)
If Not IsError(totalHTRow) And Not IsError(tvaRow) And Not IsError(totalTTCRow) Then
If totalHTRow = nextEmptyRow Or tvaRow = nextEmptyRow Or totalTTCRow = nextEmptyRow Then
nextEmptyRow = nextEmptyRow + 3
End If
End If
' Ajouter les valeurs des cellules K9 à K12 au tableau commençant à la ligne nextEmptyRow
ws.Cells(nextEmptyRow, "B").Value = Range("K9").Value
ws.Cells(nextEmptyRow, "C").Value = Range("K10").Value
ws.Cells(nextEmptyRow, "D").Value = Range("K11").Value
ws.Cells(nextEmptyRow, "E").Value = Range("K12").Value
MsgBox ("Valeurs ajoutées avec succès.")
End If
End Sub
Editor is loading...
Leave a Comment