Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Eliminer rangées selon valeur en C1

3 réponses
Avatar
Denys
Bonjour =E0 tous,

Voici une macro qui =E9limine les rang=E9es si la valeur en colonne B
n'est pas la m=EAme que celle en C1:

Sub Eliminer()
With ActiveSheet
Dim Lastrow As Integer, i As Integer
Lastrow =3D Range("B65000").End(xlUp).Row
For i =3D Lastrow To 2 Step -1
If Cells(i, 2).Row =3D 2 Then Exit Sub
If Cells(i, 2).Value <> Range("C1").Value Then Cells(i,
2).EntireRow.Delete
Next
End With
End Sub

Sauf que =E7a prend une vie..... j'ai essay=E9 avec le filtre.... mais
voici:

Sub EliminerOng()
With Worksheets("Ongoing")
Application.ScreenUpdating =3D False
With .Range("B1:B50000")
.AutoFilter Field:=3D1, Criteria1:=3D"<>Range("C1")" '<------ =C7a
marche pas ici !!!!!
.Range("_FilterDatabase").Offset(1).SpecialCells(xlCellTypeVisible)
_
.EntireRow.Delete (xlUp)
.AutoFilter
End With
End With
End Sub

Quelqu'un saurait comment filtrer en disant que le crit=E8re 1 est
"diff=E9rent de ce qui est =E9crit en C1, alors on =E9limine la ligne"

Merci pour votre temps

Denys

3 réponses

Avatar
JB
Bonsoir,

http://cjoint.com/?jlvLKDQ1I8

Sub sup_diff()
[G:G].Insert Shift:=xlToRight
[G2].Formula = "²<>C2"
[A1:E1000].AdvancedFilter Action:=xlFilterInPlace,
CriteriaRange:=[G1:G2]
If MsgBox("Etes vous sûr?", vbYesNo) = vbYes Then
Range("_FilterDataBase").Offset(1,
0).Resize(Range("_FilterDataBase"). _
Rows.Count - 1).SpecialCells(xlCellTypeVisible).Delete
Shift:=xlUp
Else
MsgBox "Annulé"
End If
ActiveSheet.ShowAllData
[G:G].Delete Shift:=xlToLeft
End Sub

JB




On 11 sep, 21:27, Denys wrote:
Bonjour à tous,

Voici une macro qui élimine les rangées si la valeur en colonne B
n'est pas la même que celle en C1:

Sub Eliminer()
With ActiveSheet
Dim Lastrow As Integer, i As Integer
Lastrow = Range("B65000").End(xlUp).Row
For i = Lastrow To 2 Step -1
If Cells(i, 2).Row = 2 Then Exit Sub
If Cells(i, 2).Value <> Range("C1").Value Then Cells(i,
2).EntireRow.Delete
Next
End With
End Sub

Sauf que ça prend une vie..... j'ai essayé avec le filtre.... mais
voici:

Sub EliminerOng()
With Worksheets("Ongoing")
Application.ScreenUpdating = False
With .Range("B1:B50000")
.AutoFilter Field:=1, Criteria1:="<>Range("C1")" '<------ Ça
marche pas ici !!!!!
.Range("_FilterDatabase").Offset(1).SpecialCells(xlCellTypeVisibl e)
_
.EntireRow.Delete (xlUp)
.AutoFilter
End With
End With
End Sub

Quelqu'un saurait comment filtrer en disant que le critère 1 est
"différent de ce qui est écrit en C1, alors on élimine la ligne"

Merci pour votre temps

Denys


Avatar
Philippe.R
Bonjour Denys,
Et si tu essayais d'ajouter Application.ScreenUpdating = False en début de
la 1ère macro + une restriction sur le recalcul

Sub Eliminer()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
With ActiveSheet
Dim Lastrow As Integer, i As Integer
Lastrow = Range("B65000").End(xlUp).Row
For i = Lastrow To 2 Step -1
If Cells(i, 2).Row = 2 Then Exit Sub
If Cells(i, 2).Value <> Range("C1").Value Then
Cells(i,2).EntireRow.Delete
Next
End With
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

en remettant tout en standard à la fin
--
Avec plaisir
Philippe.R
"Denys" a écrit dans le message de
news:
Bonjour à tous,

Voici une macro qui élimine les rangées si la valeur en colonne B
n'est pas la même que celle en C1:

Sub Eliminer()
With ActiveSheet
Dim Lastrow As Integer, i As Integer
Lastrow = Range("B65000").End(xlUp).Row
For i = Lastrow To 2 Step -1
If Cells(i, 2).Row = 2 Then Exit Sub
If Cells(i, 2).Value <> Range("C1").Value Then Cells(i,
2).EntireRow.Delete
Next
End With
End Sub

Sauf que ça prend une vie..... j'ai essayé avec le filtre.... mais
voici:

Sub EliminerOng()
With Worksheets("Ongoing")
Application.ScreenUpdating = False
With .Range("B1:B50000")
.AutoFilter Field:=1, Criteria1:="<>Range("C1")" '<------ Ça
marche pas ici !!!!!
.Range("_FilterDatabase").Offset(1).SpecialCells(xlCellTypeVisible)
_
.EntireRow.Delete (xlUp)
.AutoFilter
End With
End With
End Sub

Quelqu'un saurait comment filtrer en disant que le critère 1 est
"différent de ce qui est écrit en C1, alors on élimine la ligne"

Merci pour votre temps

Denys
Avatar
Denys
Bonjour Philippe et JB,

Merci beaucoup, ça fonctionne au quart de tour !!!

Bonne soirée

Denys