Option Explicit
Option Compare Text
Public l As Long, col As Integer
Dim Applicability As Variant, sepn As Variant
Dim Besoin As String, TBC As String
Dim cpt As Integer, DIV_Line As Integer
Dim DIV_object As Range, filter_name As Range
Dim DIV As Worksheet, Synthese As Worksheet
Dim PlageDeRecherche As Range
Dim filter As String
Dim dernligne As Integer, derncol As Integer
Sub project_filtering()
Set DIV = Sheets("DIV")
Set PlageDeRecherche = DIV.Columns(2)
Set Synthese = Sheets("Feuil1")
dernligne = Synthese.Range("A65536").End(xlUp).Row
filter = Sheets("Feuil1").Cells(1, 1).Value
'on traite le cas du sans filtre de manière simple puisque pas de filtre = on prends toutes les lignes
Select Case filter
Case Is = "No_Filter"
For l = 4 To dernligne
Synthese.Cells(l, 3) = 1
Next
' on traite le cas des autres filtres
Case Else
Set filter_name = DIV.Rows(5).Find(what:=filter, LookAt:=xlWhole)
col = filter_name.Column
For l = 4 To dernligne ' on balaye toutes les lignes de la feuille synthèse
Applicability = Synthese.Cells(l, 2).Value ' on sort l'applicabilité
' on traite l'applicabilité pour la convertir en formule binaire
Select Case Applicability
Case Is = "*"
Synthese.Cells(l, 3) = "1"
Case Else
sepn = Split(Applicability, " ") 'permet de scinder le commentaire avec le séparateur "espace"
If UBound(sepn) > -1 Then
For cpt = LBound(sepn) To UBound(sepn)
sepn(cpt) = Replace(sepn(cpt), "(", "")
sepn(cpt) = Replace(sepn(cpt), ")", "")
Set DIV_object = PlageDeRecherche.Find(what:=sepn(cpt), LookAt:=xlWhole)
If Not DIV_object Is Nothing Then
DIV_Line = DIV_object.Row
TBC = DIV.Cells(DIV_Line, col).Value
Select Case TBC
Case Is = "X" 'si c'est applicable on met "1"
Applicability = Replace(Applicability, sepn(cpt), 1, , 1)
Case Is = "?" 'par defaut on prend en compte les Applicabilités du type "?"
Applicability = Replace(Applicability, sepn(cpt), 1, , 1)
Case Else 'si c'est non-applicable on met "0"
Applicability = Replace(Applicability, sepn(cpt), 0, , 1)
End Select
End If
Next
End If
Synthese.Cells(l, 3) = Applicability
Synthese.Cells(l, "D") = EvaluationCode(Equation:=CStr(Applicability))
End Select
Synthese.Columns(3).AutoFit 'ajustement largeur
Next
End Select
MsgBox ("etape1: done")
' ici je souhaite ensuite rebalayer les lignes en convertissant la forumule binaire précédement calculée en un resultat 0 ou 1
MsgBox ("Le filtre " & filter & " a été appliqué")
End Sub
Function EvaluationCode(Optional Variable As String, Optional Equation As String)
With CreateObject("ScriptControl")
.Language = "VbScript"
.ExecuteStatement Variable & vbCrLf & "V=" & Equation
EvaluationCode = .Eval("v")
End With
End Function