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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| Function Ressources(i, R As Range) As String
'affiche les fonctions (type de ressource) correspondant à chacun des trigrammes saisis dans la colonne ressources
Dim nb, positionslash1, positionslash2, positionslash3 As Integer
Dim saisie, region, R1, R2, R3, R4 As String
saisie = i.Value
region = R.Value
''''i est la cellule contenant les ressources saisies à la main + saisie est son contenu
'définition du nb d'itérations / de concatenations
If saisie = "" Then
nb = 0
Else
nb = Len(saisie) - Len(Replace(saisie, "/", "")) + 1
End If
'AUCUNE ITERATION
If nb = 0 Then
Ressources = ""
'___'1 ITERATION
ElseIf nb = 1 Then
'def 1ère ressource seule
Ressources = Application.WorksheetFunction.VLookup(saisie, Range("tableau15[[Tri_" & region & "]:[Type_" & region & "]]"), 2, 0)
'_______'2 ITERATIONS
'def 1ère ressource --- gauche("developper",3)=dev --- gauche (saisie, instr retourne l'empl du début du mot recherché - 1 SOIT le nb de car à sortir avec left)
ElseIf nb = 2 Then
R1 = Application.WorksheetFunction.VLookup(Left(saisie, InStr(1, saisie, "/") - 1) _
, Range("tableau15[[Tri_" & region & "]:[Type_" & region & "]]"), 2, 0)
'def 2ème ressource
R2 = Application.WorksheetFunction.VLookup(Right(saisie, Len(saisie) - InStr(1, saisie, "/")) _
, Range("tableau15[[Tri_" & region & "]:[Type_" & region & "]]"), 2, 0)
Ressources = R1 & " " & R2
'___________'3 ITERATIONS
ElseIf nb = 3 Then
R1 = Application.WorksheetFunction.VLookup(Left(saisie, InStr(1, saisie, "/") - 1) _
, Range("tableau15[[Tri_" & region & "]:[Type_" & region & "]]"), 2, 0)
positionslash1 = InStr(saisie, "/")
positionslash2 = InStr(positionslash1 + 1, saisie, "/")
R2 = Application.WorksheetFunction.VLookup(Mid(saisie, positionslash1 + 1, positionslash2 - positionslash1 - 1) _
, Range("tableau15[[Tri_" & region & "]:[Type_" & region & "]]"), 2, 0)
R3 = Application.WorksheetFunction.VLookup(Right(saisie, Len(saisie) - positionslash2) _
, Range("tableau15[[Tri_" & region & "]:[Type_" & region & "]]"), 2, 0)
Ressources = R1 & " " & R2 & " " & R3
'_______________'4 ITERATIONS
ElseIf nb = 4 Then
R1 = Application.WorksheetFunction.VLookup(Left(saisie, InStr(1, saisie, "/") - 1) _
, Range("tableau15[[Tri_" & region & "]:[Type_" & region & "]]"), 2, 0)
positionslash1 = InStr(saisie, "/")
positionslash2 = InStr(positionslash1 + 1, saisie, "/")
R2 = Application.WorksheetFunction.VLookup(Mid(saisie, positionslash1 + 1, positionslash2 - positionslash1 - 1) _
, Range("tableau15[[Tri_" & region & "]:[Type_" & region & "]]"), 2, 0)
positionslash3 = InStr(positionslash2 + 1, saisie, "/")
R3 = Application.WorksheetFunction.VLookup(Mid(saisie, positionslash2 + 1, positionslash3 - positionslash2 - 1) _
, Range("tableau15[[Tri_" & region & "]:[Type_" & region & "]]"), 2, 0)
R4 = Application.WorksheetFunction.VLookup(Right(saisie, Len(saisie) - positionslash3) _
, Range("tableau15[[Tri_" & region & "]:[Type_" & region & "]]"), 2, 0)
Ressources = R1 & " " & R2 & " " & R3 & " " & R4
End If
End Function |
Partager