Macro : Supprimer lignes doubles sous conditions

  • Initiateur de la discussion Initiateur de la discussion roidurif
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

roidurif

XLDnaute Occasionnel
Bonjour,

Je souhaite faire une macro qui supprimes des lignes a deux conditions :
- Supprimer les références produits en doubles si c'est le même PRIX HT que les précédentes.
- Supprimer les lignes lorsqu'il y' a "A" colonne B

Merci de votre aide
 

Pièces jointes

Dernière édition:
Re : Macro : Supprimer lignes doubles sous conditions

Bonjour,


Code:
Sub GardeDernier()
  Set MonDico = CreateObject("Scripting.Dictionary")
  Application.ScreenUpdating = False
  i = [A65000].End(xlUp).Row
  Do While i > 2
    temp = Cells(i, "C")
    If Not MonDico.Exists(temp) Then
      MonDico.Add temp, temp
      i = i - 1
    Else
      Rows(i).EntireRow.Delete
      i = i - 1
    End If
  Loop
End Sub

Sub GardePremier()
  Set MonDico = CreateObject("Scripting.Dictionary")
  Application.ScreenUpdating = False
  i = 2
  Do While i < [A65000].End(xlUp).Row
    temp = Cells(i, "C")
    If Not MonDico.Exists(temp) Then
      MonDico.Add temp, temp
      i = i + 1
    Else
      Rows(i).EntireRow.Delete
    End If
  Loop
End Sub

Sub supA()
    [B2:B65000].SpecialCells(xlCellTypeConstants, 2).EntireRow.Delete
End Sub

JB
Formation Excel VBA JB
 

Pièces jointes

Re : Macro : Supprimer lignes doubles sous conditions

Bonjour BOISGONTIER,

Merci pour ton code, mais je viens de tester et je vois que ça supprime toutes les références produits en doubles;
Mais Par contre je ne pensais pas que ça aller tout supprimer, même les références produits en doubles avec un PRIX HT différents des précédentes. Alors que ça ne doit pas le faire.

J'espère que je m'exprime bien.

Merci pas avance et votre aide


Code:
Sub GardeDernier()
  Set MonDico = CreateObject("Scripting.Dictionary")
  Application.ScreenUpdating = False
  i = [A65000].End(xlUp).Row
  Do While i > 2
    temp = Cells(i, "C")
    If Not MonDico.Exists(temp) Then
      MonDico.Add temp, temp
      i = i - 1
    Else
      Rows(i).EntireRow.Delete
      i = i - 1
    End If
  Loop
End Sub

Sub GardePremier()
  Set MonDico = CreateObject("Scripting.Dictionary")
  Application.ScreenUpdating = False
  i = 2
  Do While i < [A65000].End(xlUp).Row
    temp = Cells(i, "C")
    If Not MonDico.Exists(temp) Then
      MonDico.Add temp, temp
      i = i + 1
    Else
      Rows(i).EntireRow.Delete
    End If
  Loop
End Sub

Sub supA()
    [B2:B65000].SpecialCells(xlCellTypeConstants, 2).EntireRow.Delete
End Sub

Cordialement
 
Re : Macro : Supprimer lignes doubles sous conditions

Bonsoir,

Code:
Sub GardeDernier()
  Set MonDico = CreateObject("Scripting.Dictionary")
  Application.ScreenUpdating = False
  i = [A65000].End(xlUp).Row
  Do While i > 2
    temp = Cells(i, "C") & Cells(i, "AH")
    If Not MonDico.Exists(temp) Then
      MonDico.Add temp, temp
      i = i - 1
    Else
      Rows(i).EntireRow.Delete
      i = i - 1
    End If
  Loop
End Sub

Sub GardePremier()
  Set MonDico = CreateObject("Scripting.Dictionary")
  Application.ScreenUpdating = False
  i = 2
  Do While i < [A65000].End(xlUp).Row
    temp = Cells(i, "C") & Cells(i, "AH")
    If Not MonDico.Exists(temp) Then
      MonDico.Add temp, temp
      i = i + 1
    Else
      Rows(i).EntireRow.Delete
    End If
  Loop
End Sub

JB
 

Pièces jointes

Dernière édition:
Re : Macro : Supprimer lignes doubles sous conditions

Bonsoir BOISGONTIER,

Merci infiniment,
Dites si je veux lancer la macro à partir de la "feuil1", comment dois je procéder?
J'ai fait cela, mais ça n'a pas l'air de fonctionner

Code:
Sub GardePremier()
  With Sheets("BDD")
  Set MonDico = CreateObject("Scripting.Dictionary")
  Application.ScreenUpdating = False
  i = 2
  Do While i < Sheets("BDD").[A65000].End(xlUp).Row
    temp = Sheets("BDD").Cells(i, "C") & Cells(i, "AH")
    If Not MonDico.Exists(temp) Then
      MonDico.Add temp, temp
      i = i + 1
    Else
      Rows(i).EntireRow.Delete
    End If
  Loop
  End With
  Call Supression_lignes_A
End Sub



Sub Supression_lignes_A()

With Sheets("BDD")
    [B2:B65000].SpecialCells(xlCellTypeConstants, 2).EntireRow.Delete
End With
End Sub

merci d'avance
 
Re : Macro : Supprimer lignes doubles sous conditions

Bonsoir,

Code:
Sub GardeDernier()
  Set f = Sheets("bdd")
  Set MonDico = CreateObject("Scripting.Dictionary")
  Application.ScreenUpdating = False
  i = f.[A65000].End(xlUp).Row
  Do While i > 2
    temp = f.Cells(i, "C") & f.Cells(i, "AH")
    If Not MonDico.Exists(temp) Then
      MonDico.Add temp, temp
      i = i - 1
    Else
      f.Rows(i).EntireRow.Delete
      i = i - 1
    End If
  Loop
End Sub

Sub GardePremier()
  Set f = Sheets("bdd")
  Set MonDico = CreateObject("Scripting.Dictionary")
  Application.ScreenUpdating = False
  i = 2
  Do While i < f.[A65000].End(xlUp).Row
    temp = f.Cells(i, "C") & f.Cells(i, "AH")
    If Not MonDico.Exists(temp) Then
      MonDico.Add temp, temp
      i = i + 1
    Else
      f.Rows(i).EntireRow.Delete
    End If
  Loop
End Sub

Sub supA()
   Set f = Sheets("bdd")
   f.[B2:B65000].SpecialCells(xlCellTypeConstants, 2).EntireRow.Delete
End Sub

JB
 

Pièces jointes

Dernière édition:
Re : Macro : Supprimer lignes doubles sous conditions

Merci BOISGONTIER,

Je me retrouve avec un cas où dans la colonne "B" est vide, la macro Sub supA() bloque.
J'ai ajouter ceci : If f.[B2:B65000] = Null Then Exit Sub
mais encore une fois je fais appel a votre aide, car j'ai du faire qq chose de pas bon

Code:
Sub supA()
   Set f = Sheets("bdd")
   If f.[B2:B65000] = Null Then Exit Sub
   f.[B2:B65000].SpecialCells(xlCellTypeConstants, 2).EntireRow.Delete
End Sub
Merci par avance

Cordialement
 
Dernière édition:
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Microsoft 365 agrandir la liste
Réponses
21
Affichages
686
Retour