Option Explicit
Const CarAutorises = "A,B,C,D,E"
Public LastColumn As Long
Public LastRow As Long
Public LastColor As Long
Public Function Init()
Dim Ligne As Long
Dim Valeurs As Variant
Dim Valeur As Variant
Sheets("Valeurs").Select
Columns("G:G").Select
Selection.ClearContents
Range("G1").Value = "Usure"
Valeurs = Split(CarAutorises, ",")
Ligne = 2
For Each Valeur In Valeurs
Range("G" & Ligne).Value = Valeur
Ligne = Ligne + 1
Next
Range("G1").Select
Sheets("Demo").Select
LastColumn = 0
LastRow = 0
End Function
Public Function ValeurValide(NewColumn, NewRow As Long)
Dim Valeur As String
Dim Result As Boolean
Dim Reponse As String
Result = True
' Verify old position
If ((LastColumn > 0) And (LastRow > 0)) Then
Valeur = UCase(Left(Trim(Cells(LastRow, LastColumn).Value), 1))
If ((Valeur = "") Or _
(Valeur = ",") Or _
(InStr(1, CarAutorises, Valeur) = 0)) Then
Application.EnableEvents = False
Cells(LastRow, LastColumn).Select
Cells(LastRow, LastColumn).Interior.ColorIndex = 38
Application.EnableEvents = True
Reponse = MsgBox("Seuls " & CarAutorises & " sont autorisés", _
vbOKOnly, "Erreur de saisie", "", 0)
Result = False
Else
Cells(LastRow, LastColumn) = Valeur
Cells(LastRow, LastColumn).Interior.ColorIndex = LastColor
End If
End If
ValeurValide = Result
End Function