Bonsoir à toutes et à tous,
après avoir cherché dans beaucoup de directions, je m'adresse à vous pour me dire quel arbre me cache la forêt …
Je suis bien conscient qu'avec with end with il faut mettre un point devant l'instruction mais du coup je me demande si je n'en mets pas un de trop
Quelle est la bonne syntaxe dans mon cas (car les deux fonctionnent !) :
Bizarrement, les deux lignes font le job (voir pièce jointe ou les toutes dernières lignes du code ci-dessous) mais j'ai peur que ça ne marche que par hasard, et qu'à l'avenir, dans un cas précis, ça coince …
Quelqu'un peut-il m'éclairer ?
Merci d'avance
après avoir cherché dans beaucoup de directions, je m'adresse à vous pour me dire quel arbre me cache la forêt …
Je suis bien conscient qu'avec with end with il faut mettre un point devant l'instruction mais du coup je me demande si je n'en mets pas un de trop
Quelle est la bonne syntaxe dans mon cas (car les deux fonctionnent !) :
Code:
Range(.Rows(Debut), .Rows(Fin)).Delete
ou
.Range(.Rows(Debut), .Rows(Fin)).Delete
Quelqu'un peut-il m'éclairer ?
Merci d'avance
Code:
Sub a0_squeeze3()
' 1 --- on trie d'abord sur le critère "Ville"
Dim lastlineVentes As Long
Dim VentesZone As Range
Dim Critere As Range
With Sheets("Ventes")
lastlineVentes = .Range("A" & Rows.Count).End(xlUp).Row
Set VentesZone = .Range("A2:E" & lastlineVentes)
Set Critere = .Range("A1") ' critère 'ville' est en colonne A
VentesZone.Sort key1:=Critere, order1:=xlAscending, Header:=xlNo
' 2 --- on définit comment trouver la ville à supprimer
Dim VilleASupprimer As String
Dim Nombre As Long
Dim ZoneOuChercher As Range
Dim DernLign As Long
Dim Debut As Long
Dim Fin As Long
VilleASupprimer = "absent de Table_client"
' 3 --- on évalue combien i y a de lignes correspondant au critère (sinon, plante qd =0)
DernLign = .Range("A" & Rows.Count).End(xlUp).Row
Set ZoneOuChercher = .Range("A1:A" & DernLign)
Nombre = Application.WorksheetFunction.CountIf(ZoneOuChercher, VilleASupprimer)
If Nombre = 0 Then
MsgBox "Ciao, aucun enregitrement avec 'absent de Table_client'"
Exit Sub
Else
MsgBox "Il y a " & Nombre & " lignes à supprimer"
Debut = WorksheetFunction.Match(VilleASupprimer, ZoneOuChercher, 0) ' 0 car correspondance exacte
Fin = WorksheetFunction.Match(VilleASupprimer, ZoneOuChercher, 1) ' 1 permet de remonter le n° de ligne juste avant le changement
' ici mes doutes ...
'Range(.Rows(Debut), .Rows(Fin)).Delete ' fonctionne SANS le point devant Range !
.Range(.Rows(Debut), .Rows(Fin)).Delete ' fonctionne AVEC le point devant Range !
End If
End With
End Sub