'### Noms des feuilles à adapter ###
Const SOURCE As String = "MASTER"
Const DEST As String = "RÉSULTAT FINAL"
'###################################
Private Sub CommandButton1_Click()
Dim Smaster As Worksheet
Dim Sfinal As Worksheet
Dim R As Range
Dim var
Dim f#
Dim g#
Dim i&
Dim j&
On Error Resume Next
Set Smaster = Sheets(SOURCE)
If Err <> 0 Then
MsgBox "La feuille " & SOURCE & " est introuvable."
Me.Hide
Exit Sub
End If
Set Sfinal = Sheets(DEST)
If Err <> 0 Then
MsgBox "La feuille " & DEST & " est introuvable."
Me.Hide
Exit Sub
End If
Err.Clear
On Error GoTo Erreur
Sfinal.Cells.Delete
Set R = Smaster.UsedRange
If R.Rows.Count < 3 Then
MsgBox "Il n'y a qu'une seule ligne de données."
Me.Hide
Exit Sub
End If
Application.ScreenUpdating = False
var = R
R.Copy
With Sfinal
.Activate
.[a1].Select
.Paste
End With
Application.CutCopyMode = False
f# = CDbl(TextBox2)
g# = CDbl(TextBox1)
For i& = 2 To UBound(var, 1)
If var(i&, 6) < f# Or var(i&, 7) < g# Then
For j& = 1 To UBound(var, 2)
var(i&, j&) = ""
Next j&
End If
Next i&
With Sfinal
Set R = .Range(R.Address)
R = var
R.Sort Key1:=.[b1], Order1:=xlAscending, Header:=xlYes
Set R = .Range("a1:g" & .[a65536].End(xlUp).Row & "")
R.Select
R.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(7), _
Replace:=True
Set R = .Range("a1:g" & .[b65536].End(xlUp).Row & "")
var = R
.Cells.EntireRow.AutoFit
For i& = 2 To UBound(var, 1)
If InStr(1, (var(i&, 2)), "Total") Then
.Range("g" & i& & "").Font.Bold = True
End If
Next i&
R = var
.Range("b" & UBound(var, 1) & "") = "Grand Total"
.Range("b" & UBound(var, 1) & ":g" & UBound(var, 1) & "").Font.ColorIndex = 5
End With
Erreur:
Sfinal.[a1].Select
Application.Goto Reference:="R1C1", Scroll:=True
Me.Hide
If Err <> 0 Then
MsgBox "Erreur " & Err.Number & vbCrLf & Err.Description
Sfinal.Cells.Delete
End If
Application.ScreenUpdating = True
End Sub