Erreur de compilation: Objet requis

Résolu
mciracing Messages postés 2 Date d'inscription mardi 7 juin 2011 Statut Membre Dernière intervention 8 juin 2011 - 7 juin 2011 à 17:34
mciracing Messages postés 2 Date d'inscription mardi 7 juin 2011 Statut Membre Dernière intervention 8 juin 2011 - 8 juin 2011 à 09:59
Bonjour à tous. Je commence à développer en VBA sur Excel. Je suis nouveau sur le forum.

J'ai un code qui fonctionné mais que je fais évolué bout par bout.
Depuis la dernière évolution:
- Ligne 53 ' Set Prow equal to existing protus line - Ligne 96 ' Fourth checking condition: existing protus --> Get information back in "New_Protus", from "Updated_Protus_List"
J'ai un message d'erreur: Erreur de compilation: Objet requis
Erreur sur la ligne 57:
"Set PRow = .Find(What:=PNNP, LookAt:=xlValues).Row"

Je n'arrive pas a résoudre ce problème.

Voici le code complet:

Option Explicit
---------------------------------------------------------------------
Public Sub Add_Protus()

' Variables declaration
Dim i As Integer
Dim k As Integer
Dim j As Integer
Dim LRNP As Integer
Dim LRAP As Integer
Dim LRUPL As Integer
Dim LRRGH As Integer
Dim RGPhase As Integer
Dim PNNP
Dim PCOM
Dim RGP
Dim EngTyp As String
Dim RUPL As Range
Dim PRow As Integer

' Update screening disable
Application.ScreenUpdating = False

' New_Protus Last Row definition
Worksheets("New_Protus").Select
LRNP = Range("A65536").End(xlUp).Row

' Add_Protus Last Row definition
Worksheets("Add_Protus").Select
LRAP = Range("K65536").End(xlUp).Row

' Updated_Protus_List Last Row definition
Worksheets("Updated_Protus_List").Select
LRUPL = Range("U65536").End(xlUp).Row

'Updated_Protus_List search range definition
Set RUPL = Range(Worksheets("Updated_Protus_List").Cells(6, 21), Worksheets("Updated_Protus_List").Cells(LRUPL, 21))

' RG_Hours Last Row definition
Worksheets("RG_Hours").Select
LRRGH = Range("B65536").End(xlUp).Row
LRRGH = LRRGH - 1

Worksheets("New_Protus").Select
'
Set k to first empty row to past protus
k = 1 + LRAP

' Action loop
For i = LRNP To 10 Step -1
' Set PNNP equal to protus number of the i row
Set PNNP = Cells(i, 2)

' Set PCOM equal to protus comment of the i row
Set PCOM = Worksheets("New_Protus").Cells(i, 13)

' Set Prow equal to existing protus line
Worksheets("Updated_Protus_List").Select
Columns(21).Select
With Selection
Set PRow = .Find(What:=PNNP, LookAt:=xlValues).Row
End With
' Engine Type definition
Worksheets("New_Protus").Select
Worksheets("New_Protus").Cells(i, 24) = "D" & Left(Worksheets("New_Protus").Cells(i, 14), 2)
' RG Phase definition
For j = 5 To LRRGH Step 1
Set RGP = Worksheets("RG_Hours").Cells(j, 2)
RGPhase = InStr(PCOM, RGP)
If RGPhase > 0 Then Worksheets("New_Protus").Cells(i, 23) = RGP
End If Next j

' Worksheets selection
Worksheets("New_Protus").Select

' First checking condition: not "L" protus --> delete the row
If Cells(i, 1) <> "L" Then
Rows(i & ":" & i).EntireRow.Delete

' Second checking condition: If not an haulage phase --> delete the row
Else
If IsEmpty(Cells(i, 23)) Then Rows(i).Delete

' Third checking condition: new protus --> copy - past to "Add_Protus" Else
If Application.WorksheetFunction.CountIf(RUPL, PNNP) = 0 Then
Range(Cells(i, 1), Cells(i, 24)).Select
Selection.Copy
Sheets("Add_Protus").Select
Cells(k, 8).Select
ActiveSheet.Paste
Sheets("New_Protus").Select
Rows(i & ":" & i).EntireRow.Delete
k = k + 1

' Fourth checking condition: existing protus --> Get information back
' in "New_Protus", from "Updated_Protus_List", just under the protus line Else
If PRow > 5 Then
Range(Cells(PRow, 20), Cells(PRow, 43)).Select
Selection.Copy
Sheets("New_Protus").Select
Cells(i + 1, 1).Paste
Selection.Interior.Color = RGB(255, 192, 0)
End If
End If
End If
End If Next i
' Update screen unable
Application.ScreenUpdating = TrueEnd Sub

Merci pour votre aide

4 réponses

cs_jopop Messages postés 1540 Date d'inscription lundi 26 mai 2003 Statut Membre Dernière intervention 1 août 2013 12
7 juin 2011 à 17:50
Salut,

où déclares-tu l'objet Selection ? Où l'assignes-tu/instancies-tu ?
En tout cas ça a pas l'air d'être dans ce bout de code.
Si Selection est null alors le .Find() dans le Width lève logiquement cette exception.
0