Знайдіть n-те входження символу в Excel – 3 швидких способи
Finding the nth occurrence of a specific character within a text string in Excel can be particularly useful in data analysis, where you might need to parse strings or extract information based on certain delimiters or patterns. For instance, let's find the 2nd or 3rd occurrence of the character "-" in a text string. I'll demonstrate straightforward techniques to efficiently accomplish this task.
Find nth occurrence of a character in text string with formula
You can craft a formula to find the nth occurrence of a character. Please do as this:
1. Enter or copy the following formula into a cell where you want to get the result:
=FIND(CHAR(1),SUBSTITUTE(A2,"-",CHAR(1),2))
- A2: The cell that contains the string.
- -: The character you are looking for.
- 2: The 2nd occurrence you want to find, you can change it to 3,4…as you need.
2. Then, drag the formula fill down to fill the formula to other cells, and the 2nd position of the character – are displayed at once, see screenshot:
- ЗАМІННИК replaces the nth occurrence of the character with a non-printable character (CHAR(1)).
- ЗНАЙТИ searches for this non-printable character, giving the position of the nth occurrence.
Find nth occurrence of a character in text string with Kutools for Excel
If you're not a fan of using formula or VBA, you might consider a convenient alternative – Kutools для Excel. Within its Formula groups, you'll find a useful utility – Знайдіть, де символ відображається N-й у рядку which quickly identifies and returns the nth position of any character in a cell.
Після встановлення Kutools для Excel, Натисніть Кутулс > Помічник формули > Помічник формули відкрити Помічник формули dialog box. Click a cell where you want to put the result. Then, do as follows:
- Select Пошук з розкривного списку Тип формули розділ;
- Вибирати Знайдіть, де символ відображається N-й у рядку in Виберіть формулу розділ;
- Select the cell which contains the string you use, then type the specified character and nth occurrence in to the textboxes in the Введення аргументів розділ;
- Нарешті клацніть OK кнопку, щоб отримати результат.
Find nth occurrence of a character in text stringl with User Defined Function
In this section, we'll explore how to create and use a UDF to find the nth occurrence of a character in Excel, providing a step-by-step guide to help you optimize your data handling.
- Утримуйте клавішу ALT + F11 і відкриває Microsoft Visual Basic для додатків вікна.
- Натисніть Insert > Модуліта вставте наступний макрос у вікно модуля.
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
- Then, close the vba window. Go back to the worksheet, enter the following formula into a cell, and then drag the fill handle down to fill the formula to other cells, see screenshot:
=FindN("-",A2,3)
- Count the number of occurrences of a word in a column
- Якщо у вас є дані стовпця, які містять кілька повторюваних значень, як показано на знімку екрана, а тепер ви хочете підрахувати кількість повторень конкретного слова в цьому стовпці. Тепер у цьому підручнику я представляю деякі трюки, щоб швидко вирішити це питання в Excel.
- Replace first n character or nth occurrence of character with another
- В Excel ми зазвичай знаходимо та замінюємо рядок функцією Знайти та замінити, але якщо ви перебуваєте в одному з наведених нижче випадків, функція Знайти та замінити вам не може допомогти.
- Extract a nth character from a string
- In general, you may want to extract string after a specific character, but in this case, I want to extract the nth character from a string as below screenshot shown.
- Extract first/last n characters from string
- Наприклад, у кожній комірці є список з довгими рядками, і ви хочете витягти перші n символів лише з кожного рядка, як перші 3 символи кожного рядка, і тепер ви можете використовувати наступні методи для його вирішення в Excel .
Статті по темі:
Найкращі інструменти продуктивності офісу
Покращуйте свої навички Excel за допомогою Kutools для Excel і відчуйте ефективність, як ніколи раніше. Kutools для Excel пропонує понад 300 додаткових функцій для підвищення продуктивності та економії часу. Натисніть тут, щоб отримати функцію, яка вам найбільше потрібна...
Вкладка Office Передає інтерфейс із вкладками в Office і значно полегшує вашу роботу
- Увімкніть редагування та читання на вкладках у Word, Excel, PowerPoint, Publisher, Access, Visio та Project.
- Відкривайте та створюйте кілька документів на нових вкладках того самого вікна, а не в нових вікнах.
- Збільшує вашу продуктивність на 50% та зменшує сотні клацань миші для вас щодня!