|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
启用宏:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim hh As Long, lh As Long, fk As Long, xh As Long
Dim dic As Object
Dim Arr As Variant
Dim sf As String
On Error Resume Next
Application.EnableEvents = False
hh = Target.Row
If Selection.Cells.CountLarge = 1 And hh > 1 Then
Set dic = CreateObject("Scripting.Dictionary")
lh = Target.Column
fk = Sheets("底稿").Cells(Rows.Count, 1).End(xlUp).Row
Arr = Sheets("底稿").Range("A1").Resize(fk, 2)
If lh = 1 Then
For xh = 2 To fk
If (Not dic.Exists(Arr(xh, 1) & "")) And Arr(xh, 1) <> "" Then dic.Add Arr(xh, 1), ""
Next xh
Else
If lh = 2 And hh <= fk And Len(Cells(hh, 1)) <> 0 Then
sf = Cells(hh, 1)
For xh = 2 To fk
If (Not dic.Exists(Arr(xh, 2) & "")) And Arr(xh, 2) <> "" And Arr(xh, 1) = sf Then dic.Add Arr(xh, 2), ""
Next xh
End If
End If
' Unprotect Password:="111" '取消分级查看表的保护密码111
If dic.Count <> 0 Then
Range("A:B").Validation.Delete
Target.Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Join(dic.Keys, ",")
Target.Validation.IgnoreBlank = True
Target.Validation.InCellDropdown = True
Target.Validation.ErrorTitle = "无效的列外名称"
Target.Validation.ErrorMessage = "不允许输入列外名称"
Target.Validation.IMEMode = xlIMEModeNoControl
Target.Validation.ShowInput = False
Target.Validation.ShowError = True
End If
End If
'Protect Password:="111", userinterfaceonly:=True '保护分级查看表的保护密码111
'EnableSelection = xlNoRestrictions '保护分级查看表锁定未锁定单元格
Set dic = Nothing
Set Arr = Nothing
Application.EnableEvents = True
End Sub
新建 Microsoft Excel 工作表.rar
(18.64 KB, 下载次数: 2)
|
评分
-
1
查看全部评分
-
|