|
本帖最后由 coby001 于 2014-10-12 11:44 编辑
- ' sheet2 的 Worksheet_Change 事件
- Private Sub Worksheet_Change(ByVal Target As Range)
- Dim r As Range, sFirstAdds$
- On Error GoTo ErrHld:
- Application.EnableEvents = False
- Do
- If Target.Column <> 1 Then Exit Do
- With Sheet1.Range("A1").CurrentRegion
- Set r = .Columns(1).Find(Target.Value)
- If Not r Is Nothing Then
- sFirstAdds = r.Address
- Target(1, 3).Validation.Delete
- Target(1, 3).Validation.Add Type:=xlValidateList, Formula1:=r(1, 2).Value
- Target(1, 2) = r(1, 3)
- Do
- Set r = .Columns(1).FindNext(r)
- If r.Address <> sFirstAdds Then
- With Target(1, 3).Validation
- .Modify Formula1:=.Formula1 & "," & r(1, 2).Value
- End With
- End If
- Loop Until r Is Nothing Or r.Address = sFirstAdds
- End If
- End With
- Loop Until True
- ErrHld:
- Application.EnableEvents = True
- End Sub
复制代码 楼主试一下。
sheet1 的 A1 开始放数据
sheet2 的 A列 输入 |
|