|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
改为输入B列“药品名称”,或点击剂型(D列)都可以:- Private Sub Worksheet_Change(ByVal Target As Range)
- If Target.Column <> 2 Or Target.Row = 1 Then Exit Sub
- If Target.Count > 1 Then Exit Sub
- If Target.Value = "" Then Exit Sub
- Call 设置(Target.Row)
- End Sub
- Private Sub Worksheet_SelectionChange(ByVal Target As Range)
- If Target.Column <> 4 Or Target.Row = 1 Then Exit Sub
- If Target.Count > 1 Then Exit Sub
- If Target.Offset(, -2).Value = "" Then Exit Sub
- Call 设置(Target.Row)
- End Sub
- Sub 设置(t&)
- Dim arr, i&, c As Range, s$
- Set d = CreateObject("scripting.dictionary")
- Set ds = CreateObject("scripting.dictionary")
- s = Cells(t, 2).Value
- With Sheets("目录表")
- Set c = .Range("c:c").Find(s, LookAt:=xlWhole)
- If Not c Is Nothing Then
- arr = .[a1].CurrentRegion
- For i = c.Row To .Range("c:c").Find(s, , LookAt:=xlWhole, SearchDirection:=xlPrevious).Row
- If Not d.Exists(arr(i, 4)) Then Set d(arr(i, 4)) = CreateObject("scripting.dictionary")
- d(arr(i, 4))(arr(i, 5)) = ""
- If Not ds.Exists(arr(i, 4) & arr(i, 5)) Then Set ds(arr(i, 4) & arr(i, 5)) = CreateObject("scripting.dictionary")
- ds(arr(i, 4) & arr(i, 5))(arr(i, 7)) = ""
- Next
- Else
- Exit Sub
- End If
- End With
- r = t
- UserForm1.ListBox1.List = d.keys
- UserForm1.Show
- End Sub
复制代码 |
|