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

weixin_53424922 2021-03-10 11:58:11


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






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
...全文
900 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

2,464

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧