Direkt zum Inhalt

Finden Sie das n-te Vorkommen eines Zeichens in Excel – 3 schnelle Möglichkeiten

Das Finden des n-ten Vorkommens eines bestimmten Zeichens innerhalb einer Textzeichenfolge in Excel kann besonders bei der Datenanalyse nützlich sein, wo Sie möglicherweise Zeichenfolgen analysieren oder Informationen basierend auf bestimmten Trennzeichen oder Mustern extrahieren müssen. Suchen wir zum Beispiel nach dem zweiten oder dritten Vorkommen des Zeichens „-“ in einer Textzeichenfolge. Ich werde einfache Techniken demonstrieren, um diese Aufgabe effizient zu erledigen.


Finden Sie mit der Formel das n-te Vorkommen eines Zeichens in einer Textzeichenfolge

Sie können eine Formel erstellen, um das n-te Vorkommen eines Zeichens zu finden. Bitte gehen Sie wie folgt vor:

1. Geben Sie die folgende Formel ein oder kopieren Sie sie in eine Zelle, in der Sie das Ergebnis erhalten möchten:

=FIND(CHAR(1),SUBSTITUTE(A2,"-",CHAR(1),2))
Note: In der obigen Formel:
  • A2: Die Zelle, die die Zeichenfolge enthält.
  • -: Der Charakter, den Sie suchen.
  • 2: Das 2. Vorkommen, das Sie finden möchten, können Sie je nach Bedarf in 3,4 ändern.

2. Ziehen Sie dann die Formelfüllung nach unten, um die Formel in andere Zellen zu füllen, und die 2. Position des Zeichens wird sofort angezeigt, siehe Screenshot:

Erklärung der Formel:
  • ERSATZ ersetzt das n-te Vorkommen des Zeichens durch ein nicht druckbares Zeichen (CHAR(1)).
  • FINDEN sucht nach diesem nicht druckbaren Zeichen und gibt die Position des n-ten Vorkommens an.

Finden Sie mit Kutools for Excel das n-te Vorkommen eines Zeichens in einer Textzeichenfolge

Wenn Sie kein Fan von Formeln oder VBA sind, könnten Sie eine praktische Alternative in Betracht ziehen – Kutools for Excel. Innerhalb der Formelgruppen finden Sie ein nützliches Dienstprogramm – Finden Sie heraus, wo das Zeichen in einer Zeichenfolge als N-te erscheint Dadurch wird schnell die n-te Position eines beliebigen Zeichens in einer Zelle identifiziert und zurückgegeben.

Nach der Installation von Kutools für Excel, klicken Kutoolen > Formel-Helfer > Formel-Helfer öffnen Formel-Helfer Dialogbox. Klicken Sie auf eine Zelle, in die Sie das Ergebnis einfügen möchten. Gehen Sie dann wie folgt vor:

  1. Auswählen Lookup aus der Dropdown-Liste von Formeltyp Sektion;
  2. Auswählen Finden Sie heraus, wo das Zeichen in einer Zeichenfolge als N-te erscheint in Wählen Sie eine Formel Sektion;
  3. Wählen Sie die Zelle aus, die die von Ihnen verwendete Zeichenfolge enthält, und geben Sie dann das angegebene Zeichen und das n-te Vorkommen in die Textfelder ein Eingabe von Argumenten Sektion;
  4. Endlich, klick OK Schaltfläche, um das Ergebnis zu erhalten.

Finden Sie das n-te Vorkommen eines Zeichens in einer Textzeichenfolge mit der benutzerdefinierten Funktion

In diesem Abschnitt erfahren Sie, wie Sie eine UDF erstellen und verwenden, um das n-te Vorkommen eines Zeichens in Excel zu finden, und bieten eine Schritt-für-Schritt-Anleitung, die Ihnen bei der Optimierung Ihrer Datenverarbeitung hilft.

  1. Halten Sie die ALT + F11 Tasten, und es öffnet die Microsoft Visual Basic für Applikationen Fenster.
  2. Klicken Sie auf Kostenlos erhalten und dann auf Installieren. Insert > Modulund fügen Sie das folgende Makro in das Modulfenster ein.
     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
  3. Schließen Sie dann das VBA-Fenster. Gehen Sie zurück zum Arbeitsblatt, geben Sie die folgende Formel in eine Zelle ein und ziehen Sie dann den Füllpunkt nach unten, um die Formel in andere Zellen zu füllen, siehe Screenshot:
    =FindN("-",A2,3)

  4. Weitere Artikel:

    • Zählen Sie, wie oft ein Wort in einer Spalte vorkommt
    • Wenn Sie über Spaltendaten verfügen, die einige doppelte Werte enthalten (siehe Abbildung unten), möchten Sie jetzt die Anzahl der Vorkommen eines bestimmten Wortes in dieser Spalte zählen. Mit diesem Tutorial stelle ich einige Tricks vor, um es schnell in Excel zu lösen.
    • Extrahieren Sie ein n-tes Zeichen aus einer Zeichenfolge
    • Im Allgemeinen möchten Sie vielleicht eine Zeichenfolge nach einem bestimmten Zeichen extrahieren, aber in diesem Fall möchte ich das n-te Zeichen aus einer Zeichenfolge extrahieren, wie im folgenden Screenshot gezeigt.
    • Extrahieren Sie die ersten/letzten n Zeichen aus der Zeichenfolge
    • Zum Beispiel gibt es in jeder Zelle eine Liste mit langen Zeichenfolgen, und Sie möchten nur die ersten n Zeichen aus jeder Zeichenfolge extrahieren, wie die ersten 3 Zeichen jeder Zeichenfolge, und jetzt können Sie sie mit den folgenden Methoden in Excel lösen .

Beste Office-Produktivitätstools

🤖 Kutools KI-Assistent: Revolutionieren Sie die Datenanalyse basierend auf: Intelligente Ausführung   |  Code generieren  |  Erstellen Sie benutzerdefinierte Formeln  |  Analysieren Sie Daten und erstellen Sie Diagramme  |  Rufen Sie Kutools-Funktionen auf...
Beliebte Funktionen: Suchen, markieren oder identifizieren Sie Duplikate   |  Leere Zeilen löschen   |  Kombinieren Sie Spalten oder Zellen, ohne Daten zu verlieren   |   Runde ohne Formel ...
Super-Lookup: VLookup mit mehreren Kriterien    VLookup mit mehreren Werten  |   VLookup über mehrere Blätter hinweg   |   Unscharfe Suche ....
Erweiterte Dropdown-Liste: Erstellen Sie schnell eine Dropdown-Liste   |  Abhängige Dropdown-Liste   |  Mehrfachauswahl Dropdown-Liste ....
Spaltenmanager: Fügen Sie eine bestimmte Anzahl von Spalten hinzu  |  Spalten verschieben  |  Schalten Sie den Sichtbarkeitsstatus ausgeblendeter Spalten um  |  Vergleichen Sie Bereiche und Spalten ...
Ausgewählte Funktionen: Rasterfokus   |  Designansicht   |   Große Formelleiste    Arbeitsmappen- und Blattmanager   |  Ressourcen (Autotext)   |  Datumsauswahl   |  Arbeitsblätter kombinieren   |  Zellen verschlüsseln/entschlüsseln    Senden Sie E-Mails nach Liste   |  Superfilter   |   Spezialfilter (Filter fett/kursiv/durchgestrichen...) ...
Top 15 Toolsets12 Text Tools (Text hinzufügen, Zeichen entfernen, ...)   |   50+ Chart Typen (Gantt-Diagramm, ...)   |   40+ Praktisch Formeln (Berechnen Sie das Alter basierend auf dem Geburtstag, ...)   |   19 Einfügen Tools (QR-Code einfügen, Bild aus Pfad einfügen, ...)   |   12 Umwandlung (Conversion) Tools (Zahlen zu Wörtern, Currency Conversion, ...)   |   7 Zusammenführen & Teilen Tools (Erweiterte Zeilen kombinieren, Zellen teilen, ...)   |   ... und mehr

Verbessern Sie Ihre Excel-Kenntnisse mit Kutools für Excel und erleben Sie Effizienz wie nie zuvor. Kutools für Excel bietet über 300 erweiterte Funktionen, um die Produktivität zu steigern und Zeit zu sparen.  Klicken Sie hier, um die Funktion zu erhalten, die Sie am meisten benötigen ...

Beschreibung


Office Tab Bringt die Oberfläche mit Registerkarten in Office und erleichtert Ihnen die Arbeit erheblich

  • Aktivieren Sie das Bearbeiten und Lesen von Registerkarten in Word, Excel und PowerPoint, Publisher, Access, Visio und Project.
  • Öffnen und erstellen Sie mehrere Dokumente in neuen Registerkarten desselben Fensters und nicht in neuen Fenstern.
  • Steigert Ihre Produktivität um 50 % und reduziert jeden Tag Hunderte von Mausklicks für Sie!
Comments (28)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Your formula to find the Nth occurrence of a character in a string does not work. Using your example, adding 2 to the results of the imbedded find ensures a starting position for the initial find of a position beyond the 1st two c's but changing the +2 to +3 does not yield the position of the 4th "c", it simply starts the search one character deeper into the string and the result is still the 3rd "c". To find the 4th "c" the search must begin beyond the position of the 3rd "c". I look forward to your new solution.
This comment was minimized by the moderator on the site
Hello, David

Yes, as you said, the first formula does not work correctly, you can apply the second formula:
=FIND(CHAR(1),SUBSTITUTE(A2,"c",CHAR(1),2))

Note: The number "2" in the formula means the second "c", if you want to get the third, fourth "c", just change the number 2 to 3,4 as you need.
Please try, hope it can help you!
This comment was minimized by the moderator on the site
Find formula1 is imperfect. It will be a great help if it is removed. I have lost lot of time trying for 4th occurance of "a" in "vedanarayanan" Thanks.
This comment was minimized by the moderator on the site
To handle the exception of the formula, you can use same with if and iserro
=IF(ISERR(FIND("c",A1,FIND("c",A1)+2)),FIND("c",A1,FIND("c",A1)+0),FIND("c",A1,FIND("c",A1)+2))
This comment was minimized by the moderator on the site
"Substitute" lets you find the Nth occurrence of a term, so combine it with "find" as follows (where 5=5th occurrence):

=FIND(CHAR(1),SUBSTITUTE(A1,"c",CHAR(1),5))
This comment was minimized by the moderator on the site
Excellent! I am glad I scrolled up to review other comments after posting my own.
This comment was minimized by the moderator on the site
This is the correct answer! please replace this whole article with this one line of code.....
This comment was minimized by the moderator on the site
The first formula is completely useless and wrong but it works just correct for this example as the first and second "c"s are adjacent. The correct formula is:


For 2nd occurence -
=FIND("c",A1,FIND("c",A1)+1)

For 3rd occurence -
=FIND("c",A1,FIND("c",A1,FIND("c",A1)+1)+1) and so on...
This comment was minimized by the moderator on the site
Absolutely agree. The +2, or +3 etc.....entirely depends on the spacing between the n and (n+1) occurences of "c". Thus you would have to manually adjust for every cell if you were trying to copy this formula down a column for instance. Essentially the same as manually counting.


Ex. Let's try to find the 4th occurrence of "c" in cell A1 using the provided formula. Per the article we should use +3 in our nested FIND function to find the 4th occurrence.


Text in Cell A1:

"cab car abc cole cube"

Manually counting, the 4th occurrence is the "c" in cole in the character position of 13.


=FIND("c",A1,FIND("c",A1)+3)

The nested function, FIND("c",A1) will find the first occurrence of "c" in position 1.

Therefore,

FIND("c",A1)+3 = 1+3 = 4

Plugging that back into our formula,

=FIND("c",A1,FIND("c",A1)+3) = FIND("c",A1,1+3) = FIND("c",A1,4)

This new formula will look for the first occurrence of "c" beginning from character position 4. The 4th character in the string is the space just after cab.

Therefore, the formula will find the "c" in car and return the value of 5 for our formula. As we know from manually counting we are looking for 13 as the output.
This comment was minimized by the moderator on the site
The firs formula works correct in my version, in the note, it has explained how to find the third or forth or nth "c".

Note: You can change the 2 in the formula based on your needs. For example, if you want to find the fourth position of "c", you can change the 2 to 3. And if you want to find the first position of "c", you shuold change 2 to 0.
This comment was minimized by the moderator on the site
Try to find out the position of the second c with the first sentence of my above comment as the string using the first formula. You'll get to know how correct it is!
This comment was minimized by the moderator on the site
Hello all,

I have a text in an Excel cell " BY TRANSFER-NEFT*HDFC0000001*N08745987123546*J0032331*KUMAR--"

I need a function to extract just "N08745987123546"

Thanks
This comment was minimized by the moderator on the site
Hello, do you want to extract the numbers after No and the number of numbers are fixed? If so, you can use Kutools for Exccel's Extract text function, type No????to extract.
This comment was minimized by the moderator on the site
HI ALL,
I have a text in an Excel cell " BY TRANSFER-NEFT*HDHC0065431*N053112345624801*K0038331*krishna--"
I need a function to extract just "N053112345624801"
This comment was minimized by the moderator on the site
Formula 1 doesn't work on fourth, fifth, sixth etc. so (+3,4,5) will always show third position of letter "c" which is 19 second formula is working though.
This comment was minimized by the moderator on the site
Hello all, I have a text in an Excel cell "23 floyd lane, longville,KN 14564" I need a function to extract just "longville" Thanks
This comment was minimized by the moderator on the site
If you must use a function, try: =TRIM(MID(A1,SEARCH(",",A1)+1,SEARCH("!@#",SUBSTITUTE(A1,",","!@#",2))-SEARCH(",",A1)-1)) Otherwise, you might consider Data > Text to Columns > Delimited (using a comma as the separator).
This comment was minimized by the moderator on the site
Try this: =INDEX(SMALL(IF(MID(A1,MATCH(ROW(INDIRECT(1&":"&LEN(A1))),ROW(INDIRECT(1&":"&LEN(A1))),0),1)="c",MATCH(ROW(INDIRECT(1&":"&LEN(A1))),ROW(INDIRECT(1&":"&LEN(A1))),0),""),MATCH(ROW(INDIRECT(1&":"&LEN(A1)-LEN(SUBSTITUTE(A1,"c","")))),ROW(INDIRECT(1&":"&LEN(A1)-LEN(SUBSTITUTE(A1,"c","")))),0)),2) where "c" is the character required and 2 is the position. Note this is an array formula.
This comment was minimized by the moderator on the site
this is simpler: =INDEX(SMALL(IF(MID(A1,ROW(INDIRECT(1&":"&LEN(A1))),1)="c",ROW(INDIRECT(1&":"&LEN(A1))),""),ROW(INDIRECT(1&":"&LEN(A1)-LEN(SUBSTITUTE(A1,"c",""))))),2)
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations