mciracing
Messages postés2Date d'inscriptionmardi 7 juin 2011StatutMembreDernière intervention 8 juin 2011
-
7 juin 2011 à 17:34
mciracing
Messages postés2Date d'inscriptionmardi 7 juin 2011StatutMembreDerniè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
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
' 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
cs_jopop
Messages postés1540Date d'inscriptionlundi 26 mai 2003StatutMembreDernière intervention 1 août 201312 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.
ucfoutu
Messages postés18038Date d'inscriptionlundi 7 décembre 2009StatutModérateurDernière intervention11 avril 2018219 7 juin 2011 à 18:11
Set PRow = .Find(What:=PNNP, LookAt:=xlValues).Row
Ouvre ton aide VBA sur le mot Row.
Row n'est pas un objet, mais un N° de ligne (d'une plage)
Ouvre maintenant ton aide en ligne sur le mot Set.
tu y liras :
Attribue une référence d'objet
, ce que n'est pas la propriété Row (bien évidemment) !
Commence donc par cet apprentissage des notions de base.
____________________
Vous aimez Codes-Sources ? Il vous aide ? Cliquez ici pour l'aider à continuer Cliquer sur "Réponse acceptée" en bas d'une solution adéquate est
cs_Jack
Messages postés14007Date d'inscriptionsamedi 29 décembre 2001StatutModérateurDernière intervention28 août 201579 7 juin 2011 à 18:36
NB : La prochaine fois, utilise la coloration syntaxique (3eme icone à droite) = conserve les indentations = plus facile à relire, parce que là, tout aligné à gauche, c'est lourd.
Merci