PB d'execution de macro

excellentt

XLDnaute Nouveau
Bonjour,

Je voudrais effacer une ligne pointée par une variable (z) et j'ai une erreur. je ne pige pas.

With Sheets("titi")
.Rows("z:z").Delete Shift:=xlUp
End With

Application.CutCopyMode = False

j'ai essayé aussi d'intégré l'enregistrement d'une macro mais sans succes

Range("A10:O10").Select
Selection.Copy
Sheets("histo").Select
Rows("9:9").Select
Selection.Insert Shift:=xlDown
Sheets("portefeuille- compte").Select
Rows("10:10").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
End Sub

sinon voila le code entier de la sub

Private Sub Worksheet_Calculate()

Dim flag As Boolean


Dim z As Integer

If flag = True Then Exit Sub
flag = True
Application.EnableEvents = False

With Sheets("portefeuille- compte")
For z = 10 To 55 Step 1


If .Cells(z, 15).Value = "VENTE" Then

.Range(.Cells(z, 1), .Cells(z, 15)).Copy


Sheets("histo").Range("A9").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Sheets("histo").Rows("9:9").Insert Shift:=xlDown
With Sheets("portefeuille- compte")
.Rows("z:z").Delete Shift:=xlUp
End With

Application.CutCopyMode = False


Else
If .Cells(z, 15).Value = "FIN" Then
Exit Sub
End If

End If

Next z
End With

flag = False
Application.EnableEvents = True

End Sub



dur dur...
 

nolich

XLDnaute Occasionnel
Re : PB d'execution de macro

Bonsoir excellentt, bonsoir à toutes et à tous :)

1ère remarque : si z est une variable, les lignes suivantes :

With Sheets("titi")
.Rows("z:z").Delete Shift:=xlUp
End With

devraient plutôt être écrites ainsi :

With Sheets("titi")
.Rows(z & ":" & z).Delete Shift:=xlUp
End With

Je n'ai pas regardé la suite...

@+
 

kjin

XLDnaute Barbatruc
Re : PB d'execution de macro

Bonsoir,
Peux tu encadrer ton code pas des balises (#) pour une meilleure lecture
Avec ce que je crois comprendre ce qui ne veut pas dire que j'ai compris
Pas compris à quoi sert le flag, pas compris pourquoi tu sors de la boucle, pas compris comment ça peut "marcher" si tu boucles du début à la fin (et non l'inverse) en supprimant des lignes !
Code:
Private Sub Worksheet_Calculate()
Dim flag As Boolean
Dim z As Integer
Application.EnableEvents = False
    With Sheets("portefeuille- compte")
        For z = 55 To 10 Step -1
            If .Cells(z, 15).Value = "VENTE" Then
                .Range(.Cells(z, 1), .Cells(z, 15)).Copy
                With Sheets("histo")
                    .Range("A9").PasteSpecial Paste:=xlValues
                    .Rows("9:9").Insert Shift:=xlDown
                End With
                Application.CutCopyMode = False
                .Rows(z).Delete
            End If
        Next z
    End With
Application.EnableEvents = True

End Sub
A+
kjin
 

Discussions similaires

Statistiques des forums

Discussions
312 228
Messages
2 086 418
Membres
103 205
dernier inscrit
zch