日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

vba有下拉框的模糊查找_Excel VBA实现渐进式模糊搜索

發(fā)布時間:2024/3/26 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vba有下拉框的模糊查找_Excel VBA实现渐进式模糊搜索 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Excel在錄入時可以匹配現(xiàn)有的內(nèi)容,但有時還是滿足不了我們的要求,以下是用Excel VBA實現(xiàn)的漸進(jìn)式模糊搜索

作者:Excel小子-Office中國

實現(xiàn)的效果:

Excel 模糊 漸進(jìn)式搜索操作動畫教程

Excel VBA實現(xiàn)漸進(jìn)式模糊搜索的主要代碼:

先放置 一個?TextBox1 文本框 及列表框?ListBox1

然后在工作表代碼中

Dim d

Dim arr, brr(0)

Dim ar

Private Sub ListBox1_Click()

End Sub

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

ActiveCell = Me.ListBox1.Value

Me.ListBox1.Visible = False

Me.TextBox1.Visible = False

ActiveCell.Select

End Sub

Private Sub ListBox1_GotFocus()

End Sub

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

If KeyCode = 13 Then

ActiveCell = ListBox1.Value

Me.ListBox1.Visible = False

Me.TextBox1.Visible = False

ActiveCell.Select

End If

End Sub

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

If WorksheetFunction.CountA(ActiveSheet.UsedRange) > 0 Then

If WorksheetFunction.CountA(ActiveSheet.UsedRange) = 1 Then

brr(0) = ActiveSheet.UsedRange

arr = brr

Else

arr = ActiveSheet.UsedRange

End If

Dim ct

Set d = CreateObject("scripting.dictionary")

If KeyCode = vbKeyDown Then

'Stop

ct = ListBox1.ListIndex + 1

If ct < ListBox1.ListCount Then ListBox1.ListIndex = ct Else ListBox1.ListIndex = 0

ElseIf KeyCode = vbKeyUp Then

ct = ListBox1.ListIndex - 1

If ct > -1 Then ListBox1.ListIndex = ct Else ListBox1.ListIndex = ListBox1.ListCount - 1

End If

If KeyCode <> 37 And KeyCode <> 39 And KeyCode <> 13 Then

For Each ar In arr

If Len(ar) > 0 Then

If InStr(ar, TextBox1.Value) = 1 Then

d(ar) = ""

End If

End If

Next ar

End If

If d.Count > 0 And Len(Me.TextBox1.Value) > 0 Then

With Me.ListBox1

.Visible = True

.Left = ActiveCell.Left + ActiveCell.Width

.Top = ActiveCell.Top

.Height = ActiveCell.Height * 5

.Width = ActiveCell.Width * 2

.List = d.keys

End With

Else

Me.ListBox1.Visible = False

End If

End If

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

On Error Resume Next

If Target.Count = 1 Then

Me.ListBox1.Visible = False

With Me.TextBox1

.Value = ""

.Visible = True

.Activate

.Left = Target.Left

.Top = Target.Top

.Width = Target.Width

.Height = Target.Height

End With

End If

End Sub

總結(jié)

以上是生活随笔為你收集整理的vba有下拉框的模糊查找_Excel VBA实现渐进式模糊搜索的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。