XL 2010 ERREUR 1004 DEFINIE PAR OBJET OU APPLICATION

laplayast

XLDnaute Occasionnel
Bonsoir,
Je veux protéger la feuille et suite à cela, j'ai l'erreur 1004. J'ai rajouté les lignes en rouge au code initial mais ce n'est pas suffisant. Merci de votre aide pour palier ce problème.

Activeworksheet.Unprotect
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not IsEmpty(celluleAvant) Then
If Not Intersect(Range(celluleAvant), [E5:LV30]) Is Nothing Then Calculate
End If
celluleAvant = Target.Address
If Not Application.Intersect(Target, Range("E5:LV30")) Is Nothing And Target.Count = 1 Then 'Adapter la plage
UserForm1.Show
End If
Calculate
Activeworksheet.Protect
End Sub
 

phlaurent55

Nous a quittés en 2020
Repose en paix
Bonjour laplayast,

Je ne pense pas que l'erreur vienne de la protection/déprotection

la ligne:
celluleAvant = Target.Address

devrait se trouver directement à la suite de:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

à+
Philippe
 

JCGL

XLDnaute Barbatruc
Bonjour à tous,
Salut Philippe et Meilleurs Vœux à toi et aux tiens.

Peux-tu essayer :

VB:
Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim CelluleAvant
CelluleAvant = Target.Address
'MsgBox CelluleAvant
If Not IsEmpty(CelluleAvant) Then
If Not Intersect(Range(CelluleAvant), [E5:LV30]) Is Nothing Then Calculate
End If
ActiveSheet.Unprotect
If Not Application.Intersect(Target, Range("E5:LV30")) Is Nothing And Target.Count = 1 Then 'Adapter la plage
MsgBox "Hello" 'UserForm1.Show
End If
Calculate
ActiveSheet.Protect
End Sub

A+ à tous

Edition : Salut Eric et Meilleurs Vœux itou
 
Dernière édition:

JCGL

XLDnaute Barbatruc
Bonjour à tous,

Peux-tu essayer avec ceci :

VB:
Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim CelluleAvant
    CelluleAvant = Target.Address
    If ActiveCell.Interior.ColorIndex <> xlNone Then Exit Sub
    If Not IsEmpty(CelluleAvant) Then
        If Not Intersect(Range(CelluleAvant), [D5:LV30]) Is Nothing Then Calculate
    End If
    ActiveSheet.Unprotect
    If Not Application.Intersect(Target, Range("D5:LV30")) Is Nothing And Target.Count = 1 Then    'Adapter la plage
        UserForm1.Show
    End If
    Calculate
    ActiveSheet.Protect
End Sub

A+ à tous
 

Discussions similaires

Réponses
1
Affichages
242

Statistiques des forums

Discussions
312 206
Messages
2 086 203
Membres
103 157
dernier inscrit
youma