excel - ActiveX 文本框,搜索输入的值
问题描述
我有一个链接到单元格 D1 的 ActiveX 文本框。
我想用它来搜索输入到文本框中的任何值。
但是,如果我想在Peter
输入后立即P
搜索,它会开始搜索,并且不会让我完成输入eter
我希望能够键入,然后按 ENTER 键查找值。
这就是我必须要做的:
Private Sub TextBox1_Change()
Dim findval As String
findval = Range("D1").Value
Cells.Find(What:=findval, After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
End Sub
我究竟做错了什么 ?
解决方案
使用KeyUp
事件会更明智,特别是Enter键:
Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Dim findval As String
If KeyCode = vbKeyReturn Then
findval = Range("D1").Value
Cells.Find(What:=findval, After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
End If
End Sub
推荐阅读
- wordpress - 按浏览次数最多对产品进行排序
- php - Laravel 上的小型管理控制面板代码
- arrays - 使用套接字发送列表
- asp.net - Go Daddy Economy Windows 托管问题与 ASP.NET 网站
- vba - Visual Basic 到 Excel 公式
- vb.net - vb.net。从所选项目播放文件
- python - django - or_ 未定义
- html - Google 表格 importxml 失败 - 无法从链接中找到正确的表格路径
- node.js - 中间件挂起
- javascript - 无法使用 this.function (React.js) 读取未定义的属性“函数”