在 Excel 中尋找某個字元第 n 次出現的位置 – 3 種快速方法
在 Excel 中的文字字串中尋找特定字元的第 n 次出現在資料分析中特別有用,您可能需要根據某些分隔符號或模式來解析字串或提取資訊。例如,讓我們尋找文字字串中第二次或第三次出現的字元“-”。我將演示有效完成此任務的簡單技術。
使用公式尋找文字字串中某個字元的第 n 次出現
您可以設計一個公式來找出某個字元的第 n 次出現。請按如下操作:
1. 將下列公式輸入或複製到要取得結果的儲存格中:
=FIND(CHAR(1),SUBSTITUTE(A2,"-",CHAR(1),2))
備註:在以上公式中:
- A2:包含字串的儲存格。
- -: 您正在尋找的角色。
- 2:您要查找的第二個出現,您可以根據需要將其變更為 2...。
2、然後,向下拖曳公式填充,將公式填入其他儲存格中,第2個位置的字元-立即顯示出來,請參閱截圖:
公式說明:
- 替代 將第 n 次出現的字元替換為不可列印字元 (CHAR(1))。
- 尋找 搜尋此不可列印字符,給出第 n 次出現的位置。
使用 Kutools for Excel 尋找文字字串中字元的第 n 次出現
如果您不喜歡使用公式或 VBA,您可能會考慮一個方便的替代方案 – Excel的Kutools。在其公式組中,您會發現一個有用的實用程式 – 查找字符在字符串中第N個出現的位置 它可以快速識別並傳回儲存格中任何字元的第 n 個位置。
安裝 Kutools for Excel 後點擊此處成為Trail Hunter 庫工具 > 公式助手 > 公式助手 打開 公式助手 對話框。按一下要放置結果的儲存格。然後,執行以下操作:
- 選擇 查找 從下拉列表中選擇 公式類型 部分;
- 選擇 查找字符在字符串中第N個出現的位置 in 選擇一個公式 部分;
- 選取包含您使用的字串的儲存格,然後在文字方塊中鍵入指定的字元和第 n 次出現的字符 參數輸入 部分;
- 最後點擊 OK 按鈕來獲得結果。
保養竅門: 對這個功能有興趣,請 點擊下載即可免費試用 30 天.
使用使用者定義函數尋找文字字串中第 n 次出現的字符
在本節中,我們將探討如何建立和使用 UDF 來尋找 Excel 中某個字元的第 n 次出現,並提供逐步指南來協助您最佳化資料處理。
- 按住 ALT + F11 鍵,然後打開 Microsoft Visual Basic for Applications 窗口。
- 點擊 插入 > 模塊,然後將以下宏粘貼到“模塊窗口”中。
Function FindN(sFindWhat As String, _ sInputString As String, N As Integer) As Integer 'Updateby Extendoffice Dim J As Integer Application.Volatile FindN = 0 For J = 1 To N FindN = InStr(FindN + 1, sInputString, sFindWhat) If FindN = 0 Then Exit For Next End Function
- 然後,關閉 vba 視窗。返回工作表,在儲存格中輸入以下公式,然後向下拖曳填充手柄將公式填入其他儲存格,請參閱螢幕截圖:
=FindN("-",A2,3)
- 計算某個單字在列中出現的次數
- 如果您有一個包含一些重複值的列數據,如下面的屏幕快照所示,那麼現在要做的就是計算該列中特定單詞出現的次數。 現在,通過本教程,我將介紹一些技巧以在Excel中快速解決該問題。
- 將前 n 個字元或第 n 個出現的字元替換為另一個字符
- 在Excel中,我們通常使用“查找和替換”功能查找和替換字符串,但是如果您屬於以下情況之一,則“查找和替換”功能無法為您提供幫助。
- 從字串中提取第 n 個字符
- 一般來說,您可能想要提取特定字符後的字串,但在這種情況下,我想從字串中提取第 n 個字符,如下圖所示。
- 從字串中提取前/後 n 個字符
- 例如,在每個單元格中都有一個包含長字符串的列表,您只想從每個字符串中提取前n個字符,就像每個字符串的前3個字符一樣,現在您可以使用以下方法在Excel中解決它。
相關文章:
最佳辦公生產力工具
🤖 | Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行 | 生成代碼 | 建立自訂公式 | 分析數據並產生圖表 | 呼叫 Kutools 函數... |
熱門特色: 尋找、突出顯示或識別重複項 | 刪除空白行 | 合併列或儲存格而不遺失數據 | 沒有公式的回合 ... | |
超級查詢: 多條件VLookup | 多值VLookup | 跨多個工作表的 VLookup | 模糊查詢 .... | |
高級下拉列表: 快速建立下拉列表 | 依賴下拉列表 | 多選下拉列表 .... | |
欄目經理: 新增特定數量的列 | 移動列 | 切換隱藏列的可見性狀態 | 比較範圍和列 ... | |
特色功能: 網格焦點 | 設計圖 | 大方程式酒吧 | 工作簿和工作表管理器 | 資源庫 (自動文字) | 日期選擇器 | 合併工作表 | 加密/解密單元格 | 按清單發送電子郵件 | 超級濾鏡 | 特殊過濾器 (過濾粗體/斜體/刪除線...)... | |
前 15 個工具集: 12 文本 工具 (添加文本, 刪除字符,...) | 50+ 圖表 類型 (甘特圖,...) | 40+ 實用 公式 (根據生日計算年齡,...) | 19 插入 工具 (插入二維碼, 從路徑插入圖片,...) | 12 轉化 工具 (數字到單詞, 貨幣兌換,...) | 7 合併與拆分 工具 (高級合併行, 分裂細胞,...) | ... 和更多 |
使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。 點擊此處獲取您最需要的功能...
Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆
- 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
- 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
- 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Sort comments by
#38962
This comment was minimized by the moderator on the site
0
0
#39007
This comment was minimized by the moderator on the site
Report
0
0
#35464
This comment was minimized by the moderator on the site
0
0
#35341
This comment was minimized by the moderator on the site
0
0
#26348
This comment was minimized by the moderator on the site
0
0
#38963
This comment was minimized by the moderator on the site
0
0
#26349
This comment was minimized by the moderator on the site
0
0
#24877
This comment was minimized by the moderator on the site
Report
0
0
#24880
This comment was minimized by the moderator on the site
Report
0
0
#24878
This comment was minimized by the moderator on the site
Report
0
0
#24879
This comment was minimized by the moderator on the site
Report
0
0
#24362
This comment was minimized by the moderator on the site
Report
0
0
#24363
This comment was minimized by the moderator on the site
Report
0
0
#24355
This comment was minimized by the moderator on the site
0
0
#20513
This comment was minimized by the moderator on the site
0
0
#17331
This comment was minimized by the moderator on the site
0
0
#17332
This comment was minimized by the moderator on the site
0
0
#13390
This comment was minimized by the moderator on the site
0
0
#13391
This comment was minimized by the moderator on the site
0
0
There are no comments posted here yet