Erreur 424
Bonjour à tous,
Je debute vraiment dans VBA. Donc j'en appelle à toutes votre indulgence...
Je suis coincée par une erreur 424 au niveau du set trouve=...
Je ne vois pas pourquoi.
MErci de votre aide précieuse
Dim i As Integer
Dim MonAgre As String, AdAgre As String
Dim MonAgreVu As String
Dim trouve As Range, PlageDeRecherche As Range
Dim NBlignes As Integer
Windows("BASEPROJETSFO.xlsm").Activate
Sheets("PROJETS FO").Activate
Rows("1:1").Select
Selection.AutoFilter
Columns("C:C").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("C1").Select
ActiveCell.FormulaR1C1 = "START DATE"
Range("A2").Select
NBlignes = Range("A2", Selection.End(xlDown)).Cells.Count
Range("B2").Select
For i = 2 To NBlignes
MonAgre = ActiveCell.Value
AdAgre = ActiveCell.Address
Selection.Copy
Windows("BASESEMAINE.xlsx").Activate
Sheets("owssvr").Activate
Set PlageDeRecherche = ActiveSheet.Columns(2)
On Error GoTo 0
Set trouve = PlageDeRecherche.Cells.Find(What:=MonAgre, LookAt:=xlWhole).Select
On Error GoTo 0
MonAgreVu = Selection.Value
If ActiveCell.Value = 0 Then
GoTo Errorhandler
End If
Selection.Activate
Selection.Offset(0, 4).Copy
Windows("BASEPROJETSFO.xlsm").Activate
Range(AdAgre).Offset(0, 1).Select
ActiveSheet.Paste
Range(AdAgre).Activate
Cells(i + 1, 2).Select
Errorhandler:
Windows("BASEPROJETSFO.xlsm").Activate
Range(AdAgre).Offset(0, 1).Name = "pas de liens"
Range(AdAgre).Activate
Cells(i + 1, 2).Select
Next
End Sub
Eneleve le "set", mets directement
trouve = PlageDeRecherche.Cells.Find(What:=MonAgre, LookAt:=xlWhole).SelectSinon, ton code en ameliore (mais je ne connais pas le but donc il est loin d'etre parfait) :
Dim i As Integer
Dim MonAgre As String, AdAgre As String
Dim MonAgreVu As String
Dim trouve As Range, PlageDeRecherche As Range
Dim NBlignes As Integer
Dim wb1 As Workbook
Set wb1 = Application.Workbooks("BASEPROJETSFO")
Dim ws1 As Worksheet
Set ws1 = wb1.Worksheets("PROJECTS FO")
Dim rng1, rng2, rng3 As Range
Set rng1 = wb1.ws1.Range("A2")
Set rng2 = wb1.ws1.Range("B2")
Set rng3 = wb1.ws1.Range("C1")
Dim wb2 As Workbook
Set wb2 = Application.Workbooks("BASESEMAINE")
Dim ws2 As Worksheet
Set ws2 = wb2.Worksheets("owssvr")
ws1.Rows("1:1").AutoFilter
Columns("C:C").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
rng3.FormulaR1C1 = "START DATE"
NBlignes = Range("A2", Selection.End(xlDown)).Cells.Count
For i = 2 To NBlignes
With rng2
MonAgre = .Value
AdAgre = .Address
.Copy
End With
Set PlageDeRecherche = ws2.Columns(2)
On Error GoTo 0
trouve = PlageDeRecherche.Cells.Find(What:=MonAgre, LookAt:=xlWhole)
On Error GoTo 0
MonAgreVu = trouve.Value
If MonAgreVu = 0 Then GoTo Errorhandler
trouve.Offset(0, 4).Copy Destination:=wb1.Range(AdAgre).Offset(0, 1)
wb1.Range(AdAgre).Cells(i + 1, 2).Select
Errorhandler:
wb1.Range(AdAgre).Offset(0, 1).Name = "pas de liens"
Range(AdAgre).Cells(i + 1, 2).Select
Next
End SubEt est-ce fait expres que le code doit lire quand meme la categorie errhandler ?
Merci beaucoup. je vais tester ça tout a l'heure.