|
本帖最后由 活在理想的世界 于 2017-10-2 13:08 编辑
VBA版本的只能先按ENTER键或者TAB键才能筛选,直接弄无法找到焦点,我试了许多次发现没有事件支持,不知楼主是否有办法?
- Private Sub Worksheet_Change(ByVal Target As Range)
- Call DD
- Dim arr(), crr()
- k = Sheet1.Range("a1048576").End(3).Row - 1
- arr = Sheet1.Range("a2").Resize(k, 2)
- For i = 1 To UBound(arr)
- If InStr(arr(i, 1), Me.Range("b" & Target.Row)) > 0 Then
- j = j + 1
- ReDim Preserve crr(1 To j)
- crr(j) = arr(i, 1)
- End If
- Next
- Sheet2.Range("b" & Target.Row).Validation.Delete
- Sheet2.Range("b" & Target.Row).Validation.Add Type:=xlValidateList, Formula1:=Join(crr, ",")
- Sheet2.Range("b" & Target.Row).Validation.ShowError = False
- End Sub
- Sub DD()
- Dim arr(), crr()
- k = Sheet1.Range("a1048576").End(3).Row - 1
- arr = Sheet1.Range("a2").Resize(k, 2)
- ReDim crr(1 To k)
- For i = 1 To UBound(arr)
- crr(i) = arr(i, 1)
- Next
- On Error Resume Next
- Sheet2.Range("b3").Resize(15, 1).Validation.Delete
- Sheet2.Range("b3").Resize(15, 1).Validation.Add Type:=xlValidateList, Formula1:=Join(crr, ",")
- Sheet2.Range("b3").Resize(15, 1).Validation.ShowError = False
- End Sub
复制代码 |
|