Excel首字拼音模糊搜索及快捷錄入
- 2017-07-11 17:54:00
- zstmtony 原創(chuàng)
- 11655
Excel獲取中文的拼音碼或拼音首字,相信大家都有見識(shí)過,在網(wǎng)上也可以搜索到很多相關(guān)的函數(shù)或VBA代碼,但根據(jù)首字拼音來進(jìn)行模糊搜索,并自動(dòng)匹配及縮小選擇范圍,并回車自動(dòng)錄入,估計(jì)很多網(wǎng)友沒有見過或嘗試過。
今天Office交流網(wǎng)就在Excel培訓(xùn)部落給大家?guī)磉@篇教程。
作者:江蘇大俠
二、動(dòng)畫顯示
三、VBA代碼
'工作表打開事件里先把清單加載到arr數(shù)組,同時(shí)提取每個(gè)商品的拼音首字母保存到brr數(shù)組。Private Sub Workbook_Open()
Dim br
arr = Sheet2.UsedRange
ReDim br(1 To UBound(arr))
For i = 1 To UBound(arr)
br(i) = pinyin(arr(i, 1))
Next
brr = br
End Sub
'ASC碼在-20319~-10247之間的為漢字,通過比較漢字在字符串中順序獲得首字母。
Public Function pinyin(ByVal r As String)
hz = "啊芭擦搭蛾發(fā)噶哈擊喀垃媽拿哦啪期然撒塌挖昔壓匝ABCDEFGHJKLMNOPQRSTWXYZZ"
For i = 1 To Len(r)
If Asc(Mid(r, i, 1)) > -10247 Or Asc(Mid(r, i, 1)) < -20319 Then
temp = Mid(r, i, 1)
Else
For j = 1 To 24
If Asc(Mid(r, i, 1)) >= Asc(Mid(hz, j, 1)) Then temp = Mid(hz, 23 + j, 1)
Next
End If
pinyin = pinyin & temp
Next
End Function
'工作表選擇事件中,如果單元格在第一列則顯示組合框,并設(shè)置組合框與單元格完全匹配。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
With ComboBox1
.Visible = False
If ActiveCell.Column = 1 Then
.Top = Target.Top: .Height = Target.Height: .Width = Target.Width: .ListWidth = 230
.Visible = True: .Activate: .Text = ActiveCell.Text
End If
End With
End Sub
'當(dāng)組合框獲得焦點(diǎn)時(shí)將arr數(shù)組加載到組合框列表中。
Private Sub ComboBox1_GotFocus()
ComboBox1.List = WorksheetFunction.Transpose(arr)
ComboBox1.DropDown
End Sub
'在組合框里輸入內(nèi)容(方向鍵和回車鍵忽略)進(jìn)行模糊搜索,可以直接輸入中文也可以輸入漢字首字母查找,加空格可以多條件,如要找330ml的可樂,可以輸入"kl 330"或者"330 kl"查找
Private Sub ComboBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode <> 37 And KeyCode <> 38 And KeyCode <> 39 And KeyCode <> 40 And KeyCode <> 13 Then
ActiveCell.Value = ComboBox1.Text
Set d = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(arr)
If InStr(1, arr(i, 1), ComboBox1.Value) > 0 Then d(arr(i, 1)) = ""
If InStr(1, brr(i), Split(ComboBox1.Value & " ", " ")(0), 1) > 0 And InStr(1, brr(i), Split(ComboBox1.Value & " ", " ")(1), 1) > 0 Then d(arr(i, 1)) = ""
Next
ComboBox1.List = d.keys
End If
End Sub
'當(dāng)在組合框里選擇或者回車時(shí),將組合框的內(nèi)容賦值到單元格。
Private Sub ComboBox1_Click()
ActiveCell = ComboBox1.Value
End Sub
Private Sub ComboBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
If ComboBox1.ListCount = 1 Then ComboBox1.ListIndex = 0
If ComboBox1.ListIndex > -1 Then ActiveCell = ComboBox1.Value
ActiveCell.Select
End If
End Sub
這個(gè)功能在企業(yè)和工廠的實(shí)際辦公場(chǎng)景有很多用途,值得學(xué)習(xí)和借鑒。
分享
Access數(shù)據(jù)庫自身
- office課程播放地址及課程明細(xì)
- Excel Word PPT Access VBA等Office技巧學(xué)習(xí)平臺(tái)
- 將( .accdb) 文件格式數(shù)據(jù)庫轉(zhuǎn)換為早期版本(.mdb)的文件格式
- 將早期的數(shù)據(jù)庫文件格式(.mdb)轉(zhuǎn)換為 (.accdb) 文件格式
- KB5002984:配置 Jet Red Database Engine 數(shù)據(jù)庫引擎和訪問連接引擎以阻止對(duì)遠(yuǎn)程數(shù)據(jù)庫的訪問(remote table)
- Access 365 /Access 2019 數(shù)據(jù)庫中哪些函數(shù)功能和屬性被沙箱模式阻止(如未啟動(dòng)宏時(shí))
- Access Runtime(運(yùn)行時(shí))最全的下載(2007 2010 2013 2016 2019 Access 365)
Access VBA函數(shù)模塊
Access Activex第三方控件
- Activex控件或Dll 在某些電腦無法正常注冊(cè)的解決辦法(regsvr32注冊(cè)時(shí)卡?。?/a>
- office使用部分控件時(shí)提示“您沒有使用該ActiveX控件許可的問題”的解決方法
- RTF文件(富文本格式)的一些解析
- Access樹控件(treeview) 64位Office下出現(xiàn)橫向滾動(dòng)條不會(huì)自動(dòng)定位的解決辦法
- Access中國樹控件 在win10電腦 節(jié)點(diǎn)行間距太小的解決辦法
- EXCEL 2019 64位版(Office 2019 64位)早就支持64位Treeview 樹控件 ListView列表等64位MSCOMMCTL.OCX控件下載
- VBA或VB6調(diào)用WebService(直接Post方式)并解析返回的XML
Access ADP Sql Server等
- 早期PB程序連接Sqlserver出現(xiàn)錯(cuò)誤
- MMC 不能打開文件C:/Program Files/Microsoft SQL Server/80/Tools/Binn/SQL Server Enterprise Manager.MSC 可能是由于文件不存在,不是一個(gè)MMC控制臺(tái),或者用后來的MMC版
- sql server連接不了的解決辦法
- localhost與127.0.0.1區(qū)別
- Roych的淺談數(shù)據(jù)庫開發(fā)系列(Sql Server)
- sqlserver 自動(dòng)備份對(duì)備份目錄沒有存取權(quán)限的解決辦法
- 安裝Sql server 2005 express 和SQLServer2005 Express版企業(yè)管理器 SQLServer2005_SSMSEE
文章分類
聯(lián)系我們
聯(lián)系人: | 王先生 |
---|---|
Email: | 18449932@qq.com |
QQ: | 18449932 |
微博: | officecn01 |