excel用vba实现下拉菜单,不知道怎么加入一个根据条件显示下拉菜单功能

weixin_53424922 weixin_53424922 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区


当判断列为否的时候,同一行的银行列点击不会出现下拉菜单,可以随意输入内容






Private Sub ListBox1_Click()
ActiveCell.Value = Me.ListBox1.Value
Me.ListBox1.Visible = False
Me.TextBox1.Visible = False
End Sub




Private Sub TextBox1_Change()
Dim arr, i%, j%, d
Set d = CreateObject("scripting.dictionary")
arr = Sheet2.Range("A1").CurrentRegion
For i = 2 To UBound(arr)
If InStr(arr(i, 1), Me.TextBox1.Value) Then
d(arr(i, 1)) = ""

End If
Next
Me.ListBox1.Clear
If d.Count >= 1 Then Me.ListBox1.List = d.keys

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Me.TextBox1.Visible = False: Me.ListBox1.Visible = False: Exit Sub
If Target.Column <> 3 Then Me.TextBox1.Visible = False: Me.ListBox1.Visible = False: Exit Sub
If Target.Row < 7 Then Me.TextBox1.Visible = False: Me.ListBox1.Visible = False: Exit Sub
Dim arr, i%, j%, d
Set d = CreateObject("scripting.dictionary")
arr = Sheet2.Range("A1").CurrentRegion
For i = 2 To UBound(arr)
d(arr(i, 1)) = ""
Next
With Me.TextBox1
.Top = Target.Top
.Left = Target.Left
.Width = Target.Width
.Height = Target.Height
.Activate
.Value = ""
.Visible = True
End With
With Me.ListBox1
.Clear
.Top = Target.Offset(0, 1).Top
.Left = Target.Offset(0, 1).Left
.Height = Target.Offset(0, 1).Height * 4
.Width = Target.Offset(0, 1).Width

.List = d.keys
.Visible = True
End With
End Sub
...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
weixin_53424922
VBA 2,506 成员 10,830 内容