Sub Extraire()
Application.ScreenUpdating = False
Dim Titre, dt As Integer, ws As Worksheet, cel As Range, n As Integer, dest As Range
Dim Deb As Long
Set ws = ThisWorkbook.Worksheets("Détail des risques")
With ws
.UsedRange.Offset(21, 0).Clear
End With
With Sheets("BDGT")
For Each cel In .Range("A11:A" & .Range("A" & Rows.Count).End(xlUp).Row)
If cel.Offset(, 1) Like "*RISK*" Then
dt = ws.Cells(Rows.Count, 1).End(xlUp).Row + 1
ws.Range("A" & dt) = cel.Offset(, 1)
ws.Range("B" & dt) = cel.Offset(, 2)
ws.Range("I" & dt) = cel.Offset(, 6)
ws.Range("J" & dt) = ws.Range("I" & dt)
End If
Next cel
End With
With ws
.Range("A" & dt + 1) = "Total"
.Range("I" & dt + 1).Formula = "=sum(I22:I" & dt & ")"
End With
dt = dt + 4 '+4 à ajuster selon le nombre de lignes à insérer
Deb = dt 'sauvegarde de la première ligne pour les OPPOR
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
With Sheets("BDGT")
For Each cel In .Range("A11:A" & .Range("A" & Rows.Count).End(xlUp).Row)
If cel.Offset(, 1) Like "*OPPOR*" Then
ws.Range("A" & dt) = cel.Offset(, 1)
ws.Range("B" & dt) = cel.Offset(, 2)
ws.Range("I" & dt) = cel.Offset(, 6)
ws.Range("J" & dt) = ws.Range("I" & dt)
dt = dt + 1
End If
Next cel
End With
With ws
.Range("A" & dt) = "Total"
.Range("I" & dt).Formula = "=sum(I" & Deb & ":I" & dt - 1 & ")"
End With
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sheets("MODELE").Rows("2:2").Copy
With ws
For i = 22 To dt
If .Range("A" & i) <> "Total" And .Range("A" & i) <> "" Then
.Rows(i).PasteSpecial Paste:=xlPasteFormats, operation:=xlNone, skipblanks:=False, Transpose:=False
End If
Next i
End With
Sheets("MODELE").Rows("3:3").Copy
With ws
For i = 22 To dt
If .Range("A" & i) = "Total" Then
.Rows(i).PasteSpecial Paste:=xlPasteFormats, operation:=xlNone, skipblanks:=False, Transpose:=False
End If
Next i
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub