Bonjour
me revoilà de retour avec un problème quand j'utilise la macro Razetsupprimefeuille
j'ai un rond rouge avec une croix blanche et 400
ou se trouve l'erreur sachant que les noms que je veux supprimer se trouvent en colonne A à partir de A3 la suppression des feuilles fonctionnent très bien.
Dans les codes suivants
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Integer
Dim Ws As Worksheet
Dim Plage As Range
Dim Nom
Application.ScreenUpdating = False
If Not Application.Intersect(Target, Range("A:A")) Is Nothing Then
If Target.Count > 1 Then Exit Sub
'Boucle sur les feuilles du classeur.
For Each Ws In ThisWorkbook.Worksheets
If Ws.Name = Target.Value Then 'même nom
MsgBox "Une feuille existe dèjà à ce nom!", vbExclamation, "Ajout feuille"
Exit Sub
End If
Next Ws
'---------------Copie modele en dernier--------------------
With Sheets("Modele")
.Select
.Range("A1") = Target.Value
.Copy After:=Sheets(Sheets.Count)
.Range("A1") = ""
End With
' renomme cette feuille avec le nom
Sheets(Sheets.Count).Name = Target.Value
'-----------------------------------------------
End If
Sheets("BDD").Activate
fin:
Application.ScreenUpdating = True
End Sub
Sub RazEtSupprimeFeuille()
Dim wsh As Worksheet
Dim rng As Range
Dim cel As Range
Set rng = Intersect(Me.UsedRange, Me.Columns(1))
If Not rng Is Nothing Then
For Each cel In rng.Cells
On Error Resume Next
Set wsh = Worksheets(cel.Text)
On Error GoTo 0
If Not wsh Is Nothing Then
Application.DisplayAlerts = False
wsh.Delete
Application.DisplayAlerts = True
End If
Set wsh = Nothing
Next cel
rng.ClearContents
End If
End Sub