|
楼主 |
发表于 2018-6-26 09:07
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 yygydong 于 2018-6-26 15:58 编辑
根据楼上excel玉米朋友的提示,有一些进步,改了下代码,可还是有些不太明白的地,求教啊。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
If Target.Count > 3 Then Exit Sub
If (Target.Column <> "1" And Target.Column <> "2") Or Target.Row < 2 Then Exit Sub
Dim t, Arr, d
Dim i&, x$, Brr, y$
Set d = CreateObject("Scripting.Dictionary")Sheet2.Unprotect Password:="123"
Sheet4.Unprotect Password:="123"
Arr = Sheet2.[b16].CurrentRegion
For i = 4 To UBound(Arr)
x = Arr(i, 3): y = Arr(i, 2)
If d.exists(x) = False Then Set d(x) = CreateObject("Scripting.Dictionary")
d(x)(y) = y
Next
If Target.Column = 2 Then ’但是这儿怎么改成6行至26行有下拉表,其它行不显示呢?没整明白,麻烦高手给看看
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=Join(d.keys, ",")
End With
Else
x = Target.Offset(0, 1).Value
If d.exists(x) Then
t = d(x).keys
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=IIf(UBound(t) <> -1, Join(t, ","), t)
End With
Else
'Target = ""
End If
End If
Sheet2.Protect Password:="123"
Sheet4.Protect Password:="123"
Application.ScreenUpdating = True
End Sub
’要在哪儿改代码才能改成6行至26行有下拉表,其它行不显示呢?没整明白,麻烦高手给看看?求教各位大神给看看。
|
|