1,502
社区成员




Private Sub 创建下拉列表框()
OLEObjects.Add ClassType:="Forms.ComboBox.1", Link:=True, DisplayAsIcon:=False, Left:=0, Top:=29, Width:=55, Height:=20
End Sub
Sub 添加列表数据()
Dim brr()
n = Range("IV3").End(xlToLeft).Column
ReDim brr(1 To n / 2)
For i = 2 To n Step 2
brr(i / 2) = Cells(3, i)
Next i
ComboBox1.List = brr
End Sub
Private Sub ComboBox1_Change()
Range("B3:IV3").Find(What:=ComboBox1.Value).Activate
End Sub
Sub CreateList()
''创建下拉列表
Dim i As Long, w1 As String
w1 = ""
With Sheet1
''首先创建下拉列表数据
For i = 2 To 6 Step 2 ''至于最后一列请自定义
w1 = w1 & IIf(w1 <> "", ",", "")
w1 = w1 & Trim$(.Cells(3, i)) & "(" & Trim$(.Cells(4, i)) & ")"
Next
''添加数据有效性
With .Range("a3").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=w1
.InCellDropdown = True
End With
End With
End Sub
'''下面是excel的事件
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address(0, 0) = "A3" Then ''将事件限制在单元格a3的改变上
Dim w1 As String
w1 = Split(Target.Value, "(")(0) ''分解出人名
Range("B3:Z3").Find(What:=w1).Activate ''利用excel的自动搜索功能
End If
End Sub