Sub macro1() For rowy = 1 To LastRow With Cells(rowy, "A") If .Value "Total" Or .Value "France telecom" Then Rows(rowy).Delete End If End With Next rowy End Sub Function LastRow() As Long Dim ix As Long ix = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count LastRow = ix End Function
Sub macro1() Dim str() As String Dim rowlast As Integer Dim flagrow As Boolean flagrow = False rowlast = Lastrow rowy = 1 While rowy <= rowlast With Cells(rowy, "A") str = Split(.Value, " ") If IsWordFound(str, "eds") Then Rows(rowy).Delete flagrow = True rowy = rowy + 1 End If 'tu peux ecrire comme cela If .Value = "Total" _ Or .Value = "France telecom" _ Or .Value = "toto" Then Rows(rowy).Delete rowy = rowy + 1 flagrow = True End If End With If Not flagrow Then rowy = rowy + 1 End If Wend End Sub Function Lastrow() As Long Dim ix As Long ix = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count Lastrow = ix End Function Function IsWordFound(lesmots() As String, worfind As String) As Boolean Dim iter As Integer Dim found As Boolean found = False For iter = 0 To UBound(lesmots) If lesmots(iter) = wordfind Then found = True End If Next iter IsWordFound = found End Function
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionSub macro1() For rowy = 1 To LastRow With Cells(rowy, "A") If .Value "Total" Or .Value "France telecom" Then Rows(rowy).Delete End If End With Next rowy End Sub Function LastRow() As Long Dim ix As Long ix = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count LastRow = ix End Function
et je voudrais garder uniquement france et germany :)
y a-t-il un moyen de supprimer des lignes lorsque la cellule contient un certain type de valeur
ex:
eds france
eds germany
Plutot que de taper tous mes mots a supprimer dans le script, je ne peux pas plutot lui demander de supprimer tous les mots qui se trouvent sur une autre page (sheet2) dans le colonne A egalement?
Sub macro1() 'efface toutes les lignes contenant le noms des entreprises du sheet2 colonne A1 to An Dim lastrowenteprise As Integer Dim lastrowlistdeleted As Integer Dim namedeleted As String Dim nameentreprise As String Dim iterdeleted As Integer Dim iterenteprise As Integer lastrowlistdeleted = Lastrow("sheet2") lastrowenteprise = Lastrow("sheet1") count = 0 For iterdeleted = 1 To lastrowlistdeleted 'loop list des entreprises to be deleted namedeleted = Sheets("sheet2").Cells(iterdeleted, "A") For iterenteprise = 1 To lastrowenteprise 'loop list entreprise nameentreprise = Sheets("sheet1").Cells(iterenteprise, "A") 'check if same name or part of name If (nameentreprise = namedeleted) Or (InStr(1, nameentreprise, namedeleted) > 0) Then Sheets("sheet1").Rows(iterenteprise).Delete iterenteprise = 0 lastrowenteprise = Lastrow("sheet1") End If Next iterenteprise Next iterdeleted End Sub Function Lastrow(sh As String) As Long Dim ix As Long ix = Sheets(sh).UsedRange.Row - 1 + Sheets(sh).UsedRange.Rows.count Lastrow = ix End Function