Private
Sub
Worksheet_Change(
ByVal
Target
As
Range)
Dim
c
As
Range, amount
As
Long
Dim
RngTo
As
Range, RngIs
As
Range
If
Intersect(Range(
"N3:N400"
), Target)
Is
Nothing
_
Or
Not
IsNumeric(Target.Value)
Then
Exit
Sub
On
Error
GoTo
fail
amount = Round(Target.Value - 1, 0)
Set
RngIs = Target.Offset(, -7)
Set
RngTo = Target.Offset(1, -7).Resize(amount)
For
Each
c
In
RngTo.Cells
If
c.Value <>
""
And
c.Value <> RngIs.Value
Then
Err.Raise 501
Next
c
Application.EnableEvents =
False
RngTo.Value = RngIs.Value
Application.EnableEvents =
True
On
Error
GoTo
0
fail:
If
Err.Number
Then
MsgBox Target.Value &
" forbidden"
End
Sub