XL 2010 Fonction personnalisée

kingfadhel

XLDnaute Impliqué
Bonsoir,
ce que je souhaite c'est d'avoir une fonction personnalisée qui:


- cherche les mots de B1 à D1 dans la colonne A
- une fois trouvée on substitue la valeur numérique qui la précède
- la dernière colonne somme les colonnes B à D
exemple :
en B4 on devrait avoir 2, en B7 ==> 3
en D2 ==> 3 (1+2)
Capture.JPG


Merci d'avance
 

Pièces jointes

  • kingfadhel.xlsm
    11.2 KB · Affichages: 12
Solution
Bonjour,

à condition qu'il y ait toujours un espace devant le mot :
VB:
Function nbV(ByVal ch As String, typ As String) As Double
    Dim tmp, i As Long
    ch = Replace(ch, " " & typ, "_" & typ)
    tmp = Split(ch, " ")
    For i = 0 To UBound(tmp)
        If InStr(tmp(i), "_" & typ) > 0 Then nbV = Val(tmp(i)): Exit For
    Next i
End Function

En B2 : =nbV($A2;B$1)
à tirer à droite et vers le bas.
eric

eriiic

XLDnaute Barbatruc
Bonjour,

à condition qu'il y ait toujours un espace devant le mot :
VB:
Function nbV(ByVal ch As String, typ As String) As Double
    Dim tmp, i As Long
    ch = Replace(ch, " " & typ, "_" & typ)
    tmp = Split(ch, " ")
    For i = 0 To UBound(tmp)
        If InStr(tmp(i), "_" & typ) > 0 Then nbV = Val(tmp(i)): Exit For
    Next i
End Function

En B2 : =nbV($A2;B$1)
à tirer à droite et vers le bas.
eric
 

kingfadhel

XLDnaute Impliqué
Bonjour,

à condition qu'il y ait toujours un espace devant le mot :
VB:
Function nbV(ByVal ch As String, typ As String) As Double
    Dim tmp, i As Long
    ch = Replace(ch, " " & typ, "_" & typ)
    tmp = Split(ch, " ")
    For i = 0 To UBound(tmp)
        If InStr(tmp(i), "_" & typ) > 0 Then nbV = Val(tmp(i)): Exit For
    Next i
End Function

En B2 : =nbV($A2;B$1)
à tirer à droite et vers le bas.
eric
@eriiiic excellent, rapide et efficace.
 

eriiic

XLDnaute Barbatruc
Tu sais que tu peux faire F1 sur les fonctions que tu ne connais pas ? Il n'y a pas beaucoup de lignes et l'aide est bien faite...
VB:
Function nbV(ByVal ch As String, typ As String) As Double
    Dim tmp, i As Long
    ch = Replace(ch, " " & typ, "_" & typ) ' remplacer les espaces devant les mots par des "_"
    tmp = Split(ch, " ") ' découper sur les espaces
    For i = 0 To UBound(tmp) ' pour chaque morceau
        ' si "_mot" est trouvé on transforme en numérique le début de chaine et on quitte la boucle
        If InStr(tmp(i), "_" & typ) > 0 Then nbV = Val(tmp(i)): Exit For
    Next i
End Function
eric
 

Discussions similaires