Lock and Format Cell Based on Cell value

megel

XLDnaute Nouveau
Hi to all,
I have 3 columns in data range A1:C15
I want that when a value in cell in column A is 0 ( zero) then corresponding cell in column C is lock and format is changed to no color (Selection.Interior.ColorIndex = xlNone, Selection.Locked = True, Selection.FormulaHidden = True )

Otherwise , If cell value in column A is another value then (Selection.Interior.ColorIndex = 2, Selection.Locked = False, and Selection.FormulaHidden = True)

This will be trigger with sheet activate
See Exemple attached

Please save my life

Merci Beaucoup

Marc
Excel 2003
 

Pièces jointes

  • Classeur1.xls
    27 KB · Affichages: 48
  • Classeur1.xls
    27 KB · Affichages: 44
  • Classeur1.xls
    27 KB · Affichages: 58

phlaurent55

Nous a quittés en 2020
Repose en paix
Re : Lock and Format Cell Based on Cell value

Bonjour megel,

ton fichier en retour,
merci de répondre en français

à+
Philippe
 

Pièces jointes

  • 111.xls
    48.5 KB · Affichages: 56
  • 111.xls
    48.5 KB · Affichages: 61
  • 111.xls
    48.5 KB · Affichages: 69

pierrejean

XLDnaute Barbatruc
Re : Lock and Format Cell Based on Cell value

Bonjour megel

a tester :

Code:
Sub test()
For n = 1 To Range("A" & Rows.Count).End(xlUp).Row
  If Range("A" & n) = 0 Then
    Range("C" & n).Interior.ColorIndex = xlNone
    Range("C" & n).Locked = True
    Range("C" & n).FormulaHidden = False
  Else
    Range("C" & n).Locked = False
    Range("C" & n).FormulaHidden = False
    Range("C" & n).Interior.ColorIndex = 4
  End If
Next
End Sub

Edit Salut Phillipe Avais pas rafraichi
 
Dernière édition:

megel

XLDnaute Nouveau
Re : Lock and Format Cell Based on Cell value

Merci Pierrejean et Philippe,
Les codes marchent bien sauf que les données dans la colonne A proviennent d'une formule et ne sont pas entrées manuellement, le code à Phillipe ne marche pas avec sheet activate ou sheet change.
Celui à Pierre marche No1 sauf que mon range est vraiment A1:A15 et non toute la colonne. Peux tu m'aider à limiter le range

Un gros merci
 

pierrejean

XLDnaute Barbatruc
Re : Lock and Format Cell Based on Cell value

Re

Voila

Code:
Sub test()
For n = 1 To 15
  If Range("A" & n) = 0 Then
    Range("C" & n).Interior.ColorIndex = xlNone
    Range("C" & n).Locked = True
    Range("C" & n).FormulaHidden = False
  Else
    Range("C" & n).Locked = False
    Range("C" & n).FormulaHidden = False
    Range("C" & n).Interior.ColorIndex = 4
  End If
Next
End Sub
 
Dernière édition:

Discussions similaires