|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
如果选择的是A列6行以下的,就添加下拉菜单(数据有效性),代码如下
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Integer, arr, ypmc As Variant, rnum As Integer
arr = Sheet1.Range("样品信息表")
If Target.Count > 1 Then Exit Sub
If Target.Row < 6 Then Exit Sub
If Target.Column = 1 Then
For i = 1 To UBound(arr)
ypmc = ypmc & arr(i, 1) & ","
Next i
ypmc = Left(ypmc, Len(ypmc) - 1)
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=ypmc
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.IMEMode = xlIMEModeNoControl
.ShowInput = True
.ShowError = False
End With
End If
End Sub
关键问题来了:代码写好后,直接操作单元格,是没有问题的,可是当我保存文档关闭后,再打开就提示需要修复,不知道哪里有问题,请大家帮忙看看,十分感谢!
|
|