Macro ne s'exécute pas correctement

Kuartz Messages postés 852 Date d'inscription   Statut Membre Dernière intervention   -  
Kuartz Messages postés 852 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

Ce code :

Sub Macro1()

Dim DL As Long, i As Long

DL = Cells(Application.Rows.Count, 1).End(xlUp).Row

For i = 2 To DL

If CStr(Range("M" & i).Value) = "FSU" Then
    Rows(i).Delete
End If

Next i

End Sub


Doit être exécuté autant de fois qu'il y a de FSU dans la colonne M. Comment cela se fait-il que toutes les lignes avec FSU ne s'effacent pas d'emblée en exécutant une seule fois le code?

1 réponse

  1. Maurice
     
    Bonjour
    ta macro modifier
    Sub Macro1()
    Dim DL As Long, I As Long
    DL = Range("M" & Rows.Count).End(xlUp).Row
       For I = DL To 2 Step -1
          If Range("M" & I).Value = "FSU" Then
              Rows(I).Delete
          End If
       Next
    End Sub
    

    A+
    Maurice
    0
    1. Kuartz Messages postés 852 Date d'inscription   Statut Membre Dernière intervention   65
       
      Merci beaucoup :)

      La même chose pour :

      On Error Resume Next
      
        If IsEmpty(Range("D1:D" & Range("D65536").End(xlUp).Row)) Then Exit Sub
        
       Application.ScreenUpdating = False ' écran(faux)
      
       For Each cell In Range("D1:D" & Range("D65536").End(xlUp).Row)
        
                          For I = 1 To Range("D65536").End(xlUp).Row
                                    Set Rng = cell.Offset(I, 0)
                                    If Rng <> "" And Rng = cell Then
                                              Range("D" & cell.Row).Select
                                              Ligne = cell.Row
                                              ' ajout des valeurs de la colonne J lors d'une détection de doublons
                                              Cells(Ligne, 18).Value = Cells(Ligne, 18).Value + Cells(Ligne + I, 18).Value
                                              ' suppression de la ligne en doublons
                                              Range(Cells(Ligne + I, 1), Cells(Ligne + I, 32)).Delete
                                              'Exit For
                                    End If
                          Next I
        Next cell


      Merci d'avance.
      0