level 1
微道微博
楼主
原代码是用窗格列出匹配项,手动选择自动填充的,我现在想要修改下。
求助大佬修改下代码,不胜感激!
如果没有选择候选窗格的内容,就清空输入值。
如果选择了候选窗格的内容,就把该内容填充到D列最后一个有内容的单元格的下一格位置,并且把该内容最后两个字的拼音首字母填充到E列对应位置。
填充内容后,检查D列的数值是否有超过6个字符相同,就弹出窗口列出有多少数值是超过6字符相同的。
网盘上有附件,里面有详细说明。求大佬下来看看修改下
链接: 百度网盘 提取码: fuhe
以下是代码:
Dim myCel As Range
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ar, br(), i&, j&, strTarget$
If Target.Count > 1 Then Exit Sub
If Target.Column <> 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
ar = Range("d1", Cells(Rows.Count, "e").End(3))
strTarget = Target.Value
For i = 1 To UBound(ar)
If InStr(ar(i, 2), strTarget) Then
r = r + 1
ReDim Preserve br(1 To r)
br(r) = ar(i, 1)
End If
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:="myCell", Position:=5)
For i = 1 To UBound(br)
With .Controls.Add(Type:=1)
.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
2024年09月09日 10点09分
1
求助大佬修改下代码,不胜感激!
如果没有选择候选窗格的内容,就清空输入值。
如果选择了候选窗格的内容,就把该内容填充到D列最后一个有内容的单元格的下一格位置,并且把该内容最后两个字的拼音首字母填充到E列对应位置。
填充内容后,检查D列的数值是否有超过6个字符相同,就弹出窗口列出有多少数值是超过6字符相同的。
网盘上有附件,里面有详细说明。求大佬下来看看修改下
链接: 百度网盘 提取码: fuhe
以下是代码:
Dim myCel As Range
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ar, br(), i&, j&, strTarget$
If Target.Count > 1 Then Exit Sub
If Target.Column <> 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
ar = Range("d1", Cells(Rows.Count, "e").End(3))
strTarget = Target.Value
For i = 1 To UBound(ar)
If InStr(ar(i, 2), strTarget) Then
r = r + 1
ReDim Preserve br(1 To r)
br(r) = ar(i, 1)
End If
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:="myCell", Position:=5)
For i = 1 To UBound(br)
With .Controls.Add(Type:=1)
.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