• Initiateur de la discussion Initiateur de la discussion fets95
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

fets95

XLDnaute Junior
Re bonjour,

Je n'arrive pas a adapté une macro que j'utilise déjà pour une recherche,
Voir fichier joint,

Pour la macro qui fonction le principe est le suivant sur un tableau je rempli les numéro de devis, sur un autre les numéro de plan la macro effectue une recherche en fonction du numéro de devis et affiche dans une cellule le numéro de plan corespondant.

Je souhaiterai reprendre le meme procédé mais cette fois ci faire la recherche en fonction du numéro de dossier.

dans la case ou se trouve les numero de plan j'ai mis la formule

=SI(B27="";findplan(A27);findplan2(A27))

Mais je n'arrive pas a creer la fonction findplan2

La macro que j'ai ecrite est la suivante :

Option Explicit

Function findplan(numdevis)
Application.Volatile ' rend la mise a jour de la fonction continue

Dim DerLig As Long, Lig As Long, VPlan As String
findplan = ""
With Sheets("N° PLAN")
DerLig = .Range("A" & Rows.Count).End(xlUp).Row ' recherche à la colonne A en partant de la derniere
For Lig = 2 To DerLig ' si trouvé lire colonne 2
VPlan = .Range("A" & Lig).Value
' Vérifier si le devis du plan correspond à la recherche
If CStr(.Range("B" & Lig)) = numdevis Then
findplan = findplan & VPlan & " " ' séparation des resultats trouvés
End If
Next Lig
End With
If Len(findplan) > 0 Then
' Enlever la dernière virgule
findplan = Left(findplan, Len(findplan) - 1)
End If
End Function
Celle ci marche bien

adaptation qui m'affiche dans la cellule #Valeur
Function findplan2(numdossier)
Application.Volatile ' rend la mise a jour de la fonction continue

Dim DerLig As Long, Lig As Long, VPlan As String
findplan2 = ""
With Sheets("Feuil2")
DerLig = .Range("A" & Rows.Count).End(xlUp).Row
For Lig = 2 To DerLig
VPlan = .Range("A" & Lig).Value
' Vérifier si le devis du plan correspond à la recherche
If CStr(.Range("C" & Lig)) = numdossier Then
findplan2 = findplan2 & VPlan & " " & "/" & " "
End If
Next Lig
End With
If Len(findplan2) > 0 Then
' Enlever la dernière virgule
findplan2 = Left(findplan2, Len(findplan2) - 1)
End If
End Function

J'espere avoir été claire dans mon probleme.

Merci a vous
 

Pièces jointes

Re : Aide pour macro

C'est bizarre : chez moi ça fonctionne, à ceci prés qu'il faut supprimer les 3 derniers caractères et non seulement le dernier.
Code:
Function findplan2(numdossier)
Application.Volatile ' rend la mise a jour de la fonction continue
Dim DerLig As Long, Lig As Long, VPlan As String

    findplan2 = ""
    With Sheets("Feuil2")
        DerLig = .Range("A" & Rows.Count).End(xlUp).Row
        For Lig = 2 To DerLig
            ' Vérifier si le devis du plan correspond à la recherche
            If CStr(.Range("C" & Lig)) = numdossier Then
                VPlan = .Range("A" & Lig).Value
                findplan2 = findplan2 & VPlan & " / "
            End If
        Next Lig
    End With
    If Len(findplan2) > 0 Then
        ' Enlever [b]les 3 derniers caractères[/b] et non la dernière virgule
        findplan2 = Left(findplan2, Len(findplan2) - [B]3[/B])
    End If
End Function


[edit]
Ben voui mais il faut mettre la bonne formule aussi...
non pas =SI(B27="";findplan(A27);findplan2(A27))
mais =SI(B27="";findplan(A27);findplan2(B27))
[/edit]
 
Dernière édition:
Re : Aide pour macro

C'est bizarre : chez moi ça fonctionne, à ceci prés qu'il faut supprimer les 3 derniers caractères et non seulement le dernier.
Code:
Function findplan2(numdossier)
Application.Volatile ' rend la mise a jour de la fonction continue
Dim DerLig As Long, Lig As Long, VPlan As String

    findplan2 = ""
    With Sheets("Feuil2")
        DerLig = .Range("A" & Rows.Count).End(xlUp).Row
        For Lig = 2 To DerLig
            ' Vérifier si le devis du plan correspond à la recherche
            If CStr(.Range("C" & Lig)) = numdossier Then
                VPlan = .Range("A" & Lig).Value
                findplan2 = findplan2 & VPlan & " / "
            End If
        Next Lig
    End With
    If Len(findplan2) > 0 Then
        ' Enlever [b]les 3 derniers caractères[/b] et non la dernière virgule
        findplan2 = Left(findplan2, Len(findplan2) - [B]3[/B])
    End If
End Function


[edit]
Ben voui mais il faut mettre la bonne formule aussi...
non pas =SI(B27="";findplan(A27);findplan2(A27))
mais =SI(B27="";findplan(A27);findplan2(B27))
[/edit]

A oui ca vient p-e de la mon erreur c'est la colonne B et pas A !!! je vais voir ca de suite 🙂

Merci bien

Etonnant je l'ai mis dans le fichier que je vous ai join cela fonctionne mais dans mon autre fichier complet il ne fonctionne pas je vais réecrir la formule p-e que cela marchera
 
Dernière édition:
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
4
Affichages
491
Réponses
10
Affichages
310
Réponses
2
Affichages
176
Réponses
2
Affichages
340
Réponses
15
Affichages
790
Retour