|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
2楼答非所问,你幸运,所以给你段代码供参考(看热闹也是种享受)。就数据有效性方案来说,达不到你的目的,参考下列Change事件方案的代码:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range, theArea As Range, theCell As Range, theValue As Variant
Dim arr As Variant, i&, theValid As Boolean
'
With Me
Set rng = Intersect(Target, .Columns(1))
If Not rng Is Nothing Then
arr = VBA.Array(1, 2, 3)
For Each theArea In rng.Areas
For Each theCell In theArea
theValid = False
theValue = theCell
For i = 0 To UBound(arr)
If theValue = arr(i) Then
theValid = True
Exit For
End If
Next i
If Not theValid Then
MsgBox "非法!"
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
GoTo The_Exit
End With
End If
Next theCell
Next theArea
End If
End With
The_Exit:
Set rng = Nothing
End Sub
|
|