Aide pour macro

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

  • Fets95_Classeur1.xls
    35 KB · Affichages: 34
  • Fets95_Classeur1.xls
    35 KB · Affichages: 35
  • Fets95_Classeur1.xls
    35 KB · Affichages: 35

TooFatBoy

XLDnaute Barbatruc
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:

fets95

XLDnaute Junior
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:

Discussions similaires

Réponses
7
Affichages
367

Statistiques des forums

Discussions
312 691
Messages
2 091 008
Membres
104 725
dernier inscrit
Marvin Foucart