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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
   | Sub Macro8()
 
    Worksheets("Filtres").Activate
    Rows("1:1").Select
    Selection.AutoFilter
    ActiveWorkbook.Worksheets("Filtres").AutoFilter.Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Filtres").AutoFilter.Sort.SortFields.Add Key:= _
        Range("A1"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.Worksheets("Filtres").AutoFilter.Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Selection.AutoFilter
 
    i = 2
    a_filtrer = ""
    While Cells(i, 2) <> ""
 
        If i = 2 Then
            If Cells(i + 1, 1) = Cells(i, 1) Then
                a_filtrer = a_filtrer & "=IF(AND(OR(R[1]C[" & -104 + Cells(i, 5) & "] = """"" & Cells(i, 4) & """"","
            Else
                a_filtrer = a_filtrer & "=IF(AND(R[1]C[" & -104 + Cells(i, 5) & "] = """"" & Cells(i, 4) & """"","
            End If
        End If
        If i > 2 Then
                If Cells(i + 1, 1) = Cells(i, 1) Then
                    If Cells(i + 1, 1) <> "" Then
                        a_filtrer = a_filtrer & " OR(R[1]C[" & -104 + Cells(i, 5) & "] = """"" & Cells(i, 4) & """"","
                    Else
                        a_filtrer = a_filtrer & " OR(R[1]C[" & -104 + Cells(i, 5) & "] = """"" & Cells(i, 4) & """"""
                    End If
                ElseIf Cells(i + 1, 1) <> Cells(i, 1) And Cells(i - 1, 1) = Cells(i, 1) Then
                    If Cells(i + 1, 1) <> "" Then
                        a_filtrer = a_filtrer & " R[1]C[" & -104 + Cells(i, 5) & "] = """"" & Cells(i, 4) & """""),"
                    Else
                        a_filtrer = a_filtrer & " R[1]C[" & -104 + Cells(i, 5) & "] = """"" & Cells(i, 4) & """"")"
                    End If
                Else
                    If Cells(i + 1, 1) <> "" Then
                        a_filtrer = a_filtrer & " R[1]C[" & -104 + Cells(i, 5) & "] = """"" & Cells(i, 4) & """"","
                    Else
                        a_filtrer = a_filtrer & " R[1]C[" & -104 + Cells(i, 5) & "] = """"" & Cells(i, 4) & """""),1,0)"
                    End If
                End If
        End If
 
        i = i + 1
    Wend
    MsgBox (a_filtrer)
    Cells(1, 104).FormulaR1C1 = a_filtrer
    Cells(1, 104).FormulaR1C1 = "=IF(AND(OR(R[1]C[-98] = ""Un homme"", R[1]C[-98] = ""Une femme""), R[1]C[-90] = ""01 - Oui"", R[1]C[-97] = ""01 - CSP+"", OR(R[1]C[-95] = ""10-17 ans"", R[1]C[-95] = ""18-25 ans"")),1,0)"
 
 
End Sub |