Bonjour à tous,

Voila je débute en VBA et je cherche désespérément à effectuer une rechercheV dans une feuille d'un autre classeur en utilisant une variable. Car le nom de mon classeur (exemple Probat1, Probat2...) peut varier mais pas la feuille (Prem's).

Mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Sub Probat()
 
    Columns("F:F").Select
    Selection.Find(What:="Total à périmètre comparable" & Chr(10) & "PLATRE" & Chr(10) & "CIMENT", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
        lgfin1 = ActiveCell.Row - 1
        ActiveSheet.Cells(2, 10).Value = lgfin1
 
            Columns("F:F").Select
    Selection.Find(What:="Total GENERAL" & Chr(10) & "PLATRE" & Chr(10) & "CIMENT", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
        lgfin2 = ActiveCell.Row - 4
        ActiveSheet.Cells(2, 10).Value = lgfin2  
 
For nbcell = 2 To lgfin1
 
    ActiveSheet.Cells(nbcell, 10).Formula = "=VLOOKUP(RC[-8],'[Probat]Prem''s'!C2:C8,7,FALSE)"
 
Next nbcell
 
For nbcell = lgfin1 + 4 To lgfin2
 
   ActiveSheet.Cells(nbcell, 10).Formula = "=VLOOKUP(RC[-8],'[Probat]Prem''s'!C2:C8,7,FALSE)"
 
Next nbcell
 
End Sub
Merci de votre précieuse