免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
Excel首字拼音模糊搜索及快捷錄入

Excel獲取中文的拼音碼或拼音首字,相信大家都有見(jiàn)識(shí)過(guò),在網(wǎng)上也可以搜索到很多相關(guān)的函數(shù)或VBA代碼,但根據(jù)首字拼音來(lái)進(jìn)行模糊搜索,并自動(dòng)匹配及縮小選擇范圍,并回車(chē)自動(dòng)錄入,估計(jì)很多網(wǎng)友沒(méi)有見(jiàn)過(guò)或嘗試過(guò)。

今天Office交流網(wǎng)就在Excel培訓(xùn)部落給大家?guī)?lái)這篇教程。


一、實(shí)現(xiàn)效果


作者:江蘇大俠





二、動(dòng)畫(huà)顯示



三、VBA代碼

'工作表打開(kāi)事件里先把清單加載到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之間的為漢字,通過(guò)比較漢字在字符串中順序獲得首字母。
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)容(方向鍵和回車(chē)鍵忽略)進(jìn)行模糊搜索,可以直接輸入中文也可以輸入漢字首字母查找,加空格可以多條件,如要找330ml的可樂(lè),可以輸入"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)在組合框里選擇或者回車(chē)時(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è)和工廠(chǎng)的實(shí)際辦公場(chǎng)景有很多用途,值得學(xué)習(xí)和借鑒。
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
【20180309】- Excel VBA智能提示,實(shí)現(xiàn)快速輸入
自學(xué)資料(Excel VBA)[收集整理2]
excl 窗體錄入數(shù)據(jù)(字母或漢字)自動(dòng)下拉單
Excel之VBA常用功能應(yīng)用篇:VBA實(shí)現(xiàn)跳轉(zhuǎn)到工作表任意位置
細(xì)品RibbonX(55):在Visual Studio中開(kāi)發(fā)Excel商務(wù)應(yīng)用程序(1)
Vba實(shí)現(xiàn)Excel感知下拉列表
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服