Private Sub CmdActualiser_Click()
Dim plage As Range, cel As Range, lig%, k%, rw
Dim Msg As Integer, id, art, num
Msg = MsgBox("Êtes-vous sûr de vouloir supprimer les données ?", vbYesNo, "LES MILLES MERVEILLES")
If Msg = 6 Then
With ListView1
id = .SelectedItem.Index
.ListItems(id).Selected = True
art = .ListItems(id).ListSubItems(1)
With WsRetours
lig = .Range("a65536").End(xlUp).Row + 1
.Cells(lig, 1) = lig - 1
.Cells(lig, 2) = CmbComm.Value
.Cells(lig, 3) = TxtClient
.Cells(lig, 4) = LvItem.SubItems(1)
.Cells(lig, 5) = TxtRetours.Value
.Cells(lig, 6) = LvItem.SubItems(3)
.Cells(lig, 7) = LvItem.SubItems(4)
.Columns.AutoFit
End With
With WsDC
Set plage = .Range("b2:b" & Range("b65536").End(xlUp).Row).Find(Val(CmbComm))
For Each cel In plage
Set cel = .Range("c2:c" & Range("c65536").End(xlDown).Row).Find(art)
cel.Offset(0, 0).EntireRow.Delete xlUp
Next cel
lig = .Range("a65536").End(xlUp).Row
For k = 2 To lig
.Cells(k, 1) = k - 1
Next k
Call MontantFacture
End With
With WsSav
Set plage = .Range("b2:b" & Range("b65536").End(xlUp).Row).Find(Val(CmbComm))
For Each cel In plage
Set cel = .Range("b2:b" & Range("b65536").End(xlDown).Row).Find(art)
cel.Offset(0, 0).EntireRow.Delete xlUp
Next cel
End With
With WsStock
rw = Application.Match(art, .Columns(3), 0)
.Cells(rw, 9) = .Cells(rw, 9) - TxtRetours
.Cells(rw, 11) = .Cells(rw, 11) + TxtRetours
TxtStockReel = .Cells(rw, 11)
End With
.ListItems.Remove id
MsgBox "Données supprimées.", vbOK, "LES MILLES MERVEILLES"
If Msg = 7 Then Exit Sub
End With
End If
End Sub
Private Sub CmdTout_Click()
Dim plage As Range, cel As Range
Dim Msg%, lig%, j%, k%
Dim id, art, num, nb, rw
Msg = MsgBox("Êtes-vous sûr de vouloir supprimer toute la commande ?", vbYesNo, "LES MILLES MERVEILLES")
If Msg = 6 Then
With WsC
rw = WorksheetFunction.Match(Val(CmbComm), .Columns(2), 0)
.Cells(rw, 2).EntireRow.Delete
End With
With WsFact
rw = WorksheetFunction.Match(Val(CmbComm), .Columns(2), 0)
.Cells(rw, 2).EntireRow.Delete
End With
With ListView1
id = .SelectedItem.Index
art = .ListItems(id).ListSubItems(1)
With WsRetours
lig = .Range("a65536").End(xlUp).Row + 1
For j = 1 To Me.ListView1.ListItems.Count
.Cells(lig, 1) = lig - 1
.Cells(lig, 2) = CmbComm.Value
.Cells(lig, 3) = TxtClient
.Cells(lig, 4) = Me.ListView1.ListItems(j).SubItems(1)
.Cells(lig, 5) = Me.ListView1.ListItems(j).SubItems(2)
.Cells(lig, 6) = Me.ListView1.ListItems(j).SubItems(3)
.Cells(lig, 7) = Me.ListView1.ListItems(j).SubItems(4)
lig = lig + 1
Next j
.Columns.AutoFit
End With
With WsDC
rw = WorksheetFunction.Match(Val(CmbComm), .Columns(2), 0)
nb = WorksheetFunction.CountIf(.Columns(2), Val(CmbComm))
.Cells(rw, "B").Resize(nb).EntireRow.Delete
lig = .Range("a65536").End(xlUp).Row
For k = 2 To lig
.Cells(k, 1) = k - 1
Next k
Call MontantFacture
End With
With WsStock
For j = 1 To Me.ListView1.ListItems.Count
rw = rw + 1
rw = Application.Match(Me.ListView1.ListItems(j).SubItems(1), .Columns(3), 0)
.Cells(rw, 9) = .Cells(rw, 9) - Me.ListView1.ListItems(j).SubItems(2)
.Cells(rw, 11) = .Cells(rw, 11) + Me.ListView1.ListItems(j).SubItems(2)
Next j
End With
With WsSav
rw = WorksheetFunction.Match(Val(CmbComm), .Columns(2), 0)
k = .Cells(rw, "B").CurrentRegion.Rows.Count + 1
.Cells(rw, "B").Resize(k).EntireRow.Delete
End With
.ListItems.Clear
MsgBox "La commande à été supprimée.", vbOK, "LES MILLES MERVEILLES"
If Msg = 7 Then Exit Sub
End With
End If
End Sub