|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 百读谷歌 于 2023-4-17 11:36 编辑
这个代码是匹配B列输入的内容,如果和S列的内容有匹配就自动填入或者给出选择框手动选择填入
原本在原表格可以使用,但是我把这个代码复制到新表格后就不能使用,一直报错。
哪位大神给看看是问题出在哪里了?
哪里做错了?
Dim myCel As Range
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ar, br(), i&, j&, strTarget$
If Target.Count > 2 Then Exit Sub
If Target.Column <> 2 Then Exit Sub
If Target.Value = "" Then Exit Sub
ar = Range("S1", Cells(Rows.Count, "S").End(3))
strTarget = Target.Value
For i = 1 To UBound(ar)
If InStr(ar(i, 1), strTarget) Then
r = r + 1
ReDim Preserve br(1 To r)
br(r) = ar(i, 1)
End If
Next i
Set myCel = Target
If r = 0 Then
MsgBox "未找到"
Application.EnableEvents = False
Target.Value = ""
Application.EnableEvents = True
Exit Sub
End If
If r = 1 Then
Application.EnableEvents = False
myCel = br(r)
Application.EnableEvents = True
Exit Sub
End If
With Application.CommandBars.Add(Name:="my112Cell", Position:=msoBarPopup)
For i = 1 To UBound(br)
With .Controls.Add(Type:=msoControlButton)
.Caption = br(i)
.OnAction = "Sheet1.myCellAction"
End With
Next
.ShowPopup
.Delete
End With
Set myCel = Nothing
End Sub
Sub myCellAction()
Application.EnableEvents = False
myCel = Application.CommandBars.ActionControl.Caption
Application.EnableEvents = True
End Sub
|
|