1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| Sub subDaniel()
Dim oRngPos As Excel.Range, oRngNeg As Excel.Range, oRngNeutr As Excel.Range
Dim l As Long
Const iLigne As Long = 5 'numéro de ligne renseignée sur les feuilles (valeur à adapter).
Dim oSh As Excel.Worksheet
Set oSh = ThisWorkbook.Worksheets("SYNTHESE")
l = oSh.UsedRange.Rows(oSh.UsedRange.Rows.Count).Row
'on considère que dans SYNTHESE, les titres sont en ligne 3 et 4, effacer les résultats précédents
If l > 4 Then oSh.Rows("5:" & l).ClearContents
'initialiser les "signets" des 3 tableaux. En ABC = Pos; En EFG = Neg; En IJK = Neutr
Set oRngPos = oSh.Range("A5")
Set oRngNeg = oSh.Range("E5")
Set oRngNeutr = oSh.Range("I5")
'rechercher les infos dans les feuilles
For Each oSh In ThisWorkbook.Worksheets
If oSh.Name <> "SYNTHESE" Then
Select Case oSh.Range("A" & iLigne).Value
Case "CF POSITIVE"
Call subAddSynth(oSh, oRngPos, iLigne)
Case "CF NEGATIVE"
Call subAddSynth(oSh, oRngNeg, iLigne)
Case "CF NEUTRE"
Call subAddSynth(oSh, oRngNeutr, iLigne)
End Select
End If
Next oSh
Set oSh = Nothing
End Sub
Sub subAddSynth(ByVal oSh As Excel.Worksheet, ByRef oRng As Excel.Range, ByVal iLigne As Long)
'ajoute une ligne à un tableau Pos, Neg ou Neutr, suivant oRng
oRng.Value = oSh.Range("B" & iLigne).Value
oRng.Offset(0, 1).Value = oSh.Range("C" & iLigne).Value
oRng.Offset(0, 2).Value = oSh.Range("D" & iLigne).Value
Set oRng = oRng.Offset(1, 0) 'passer à la ligne suivante
End Sub |
Partager