Vai al contenuto principale

Trova l'ennesima occorrenza di un carattere in Excel: 3 modi rapidi

Trovare l'ennesima occorrenza di un carattere specifico all'interno di una stringa di testo in Excel può essere particolarmente utile nell'analisi dei dati, dove potrebbe essere necessario analizzare stringhe o estrarre informazioni in base a determinati delimitatori o modelli. Ad esempio, troviamo la seconda o la terza occorrenza del carattere "-" in una stringa di testo. Dimostrerò tecniche semplici per eseguire in modo efficiente questo compito.


Trova l'ennesima occorrenza di un carattere nella stringa di testo con la formula

Puoi creare una formula per trovare l'ennesima occorrenza di un personaggio. Per favore fai così:

1. Inserisci o copia la seguente formula in una cella in cui desideri ottenere il risultato:

=FIND(CHAR(1),SUBSTITUTE(A2,"-",CHAR(1),2))
Note:: Nella formula sopra:
  • A2: la cella che contiene la stringa.
  • -: Il personaggio che stai cercando.
  • 2: La seconda occorrenza che desideri trovare, puoi modificarla in 2...secondo le tue necessità.

2. Quindi, trascina il riempimento della formula verso il basso per riempire la formula in altre celle e la seconda posizione del carattere viene visualizzata contemporaneamente, vedi screenshot:

Spiegazione della formula:
  • SOSTITUIRE sostituisce l'ennesima occorrenza del carattere con un carattere non stampabile (CHAR(1)).
  • TROVA cerca questo carattere non stampabile, fornendo la posizione dell'ennesima occorrenza.

Trova l'ennesima occorrenza di un carattere nella stringa di testo con Kutools per Excel

Se non sei un fan dell'utilizzo di formule o VBA, potresti prendere in considerazione un'alternativa conveniente: Kutools for Excel. All'interno dei gruppi Formula troverai un'utilità utile: Trova dove appare il carattere Ennesimo in una stringa che identifica e restituisce rapidamente l'ennesima posizione di qualsiasi carattere in una cella.

Dopo aver installato Kutools per Excel, fare clic su Kutools > formula Helper > formula Helper per aprire il formula Helper la finestra di dialogo. Fai clic su una cella in cui desideri inserire il risultato. Quindi, procedi come segue:

  1. Seleziona Lookup dall'elenco a discesa di Tipo di formula sezione;
  2. Scegli Trova dove appare il carattere Ennesimo in una stringa in Scegli una formula sezione;
  3. Seleziona la cella che contiene la stringa che usi, quindi digita il carattere specificato e l'ennesima occorrenza nelle caselle di testo in Input di argomenti sezione;
  4. Finalmente, clicca OK pulsante per ottenere il risultato.
Suggerimenti:: Interessato a questa funzione, per favore fare clic per scaricare per ottenere una prova gratuita per 30 giorni.

Trova l'ennesima occorrenza di un carattere nella stringa di testo con la funzione definita dall'utente

In questa sezione esploreremo come creare e utilizzare una UDF per trovare l'ennesima occorrenza di un carattere in Excel, fornendo una guida passo passo per aiutarti a ottimizzare la gestione dei dati.

  1. Tenere premuto il tasto ALT + F11 chiavi e apre il file Microsoft Visual Basic, Applications Edition finestra.
  2. Clicchi inserire > Modulie incolla la seguente macro nella finestra del modulo.
     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. Quindi, chiudi la finestra vba. Torna al foglio di lavoro, inserisci la seguente formula in una cella, quindi trascina verso il basso il quadratino di riempimento per riempire la formula in altre celle, vedi screenshot:
    =FindN("-",A2,3)

  4. Articoli Correlati:

    • Contare il numero di occorrenze di una parola in una colonna
    • Se hai una colonna di dati che include alcuni valori duplicati come mostrato nell'immagine sottostante, e ora quello che vuoi fare è contare il numero di occorrenze di una parola specifica in questa colonna. Ora con questo tutorial, presento alcuni trucchi per risolverlo rapidamente in Excel.
    • Estrae un ennesimo carattere da una stringa
    • In generale, potresti voler estrarre la stringa dopo un carattere specifico, ma in questo caso, voglio estrarre l'ennesimo carattere da una stringa come mostrato nell'immagine sottostante.
    • Estrai il primo/ultimo n caratteri dalla stringa
    • Ad esempio, c'è un elenco con stringhe lunghe in ogni cella e vuoi estrarre solo i primi n caratteri da ogni stringa, come i primi 3 caratteri di ogni stringa, e ora puoi usare i seguenti metodi per risolverlo in Excel .

I migliori strumenti per la produttività in ufficio

🤖 Assistente AI di Kutools: Rivoluziona l'analisi dei dati basandosi su: Esecuzione intelligente   |  Genera codice  |  Crea formule personalizzate  |  Analizzare i dati e generare grafici  |  Richiama le funzioni di Kutools...
Funzioni popolari: Trova, evidenzia o identifica i duplicati   |  Elimina righe vuote   |  Combina colonne o celle senza perdere dati   |   Round senza formula ...
Super ricerca: VLookup a criteri multipli    VLookup a valori multipli  |   VLookup su più fogli   |   Ricerca fuzzy ....
Elenco a discesa avanzato: Crea rapidamente un elenco a discesa   |  Elenco a discesa dipendente   |  Elenco a discesa a selezione multipla ....
Gestore di colonna: Aggiungi un numero specifico di colonne  |  Sposta colonne  |  Attiva/disattiva lo stato di visibilità delle colonne nascoste  |  Confronta intervalli e colonne ...
Funzionalità in primo piano: Messa a fuoco della griglia   |  Vista di progettazione   |   Grande barra delle formule    Gestore di cartelle di lavoro e fogli   |  Resource Library (Testo automatico)   |  Date picker   |  Combina fogli di lavoro   |  Crittografa/decrittografa le celle    Invia e-mail per elenco   |  Super filtro   |   Filtro speciale (filtro grassetto/corsivo/barrato...) ...
I 15 migliori set di strumenti12 Testo Strumenti (aggiungi testo, Rimuovi personaggi, ...)   |   50+ Grafico Tipi (Diagramma di Gantt, ...)   |   40+ Pratico Formule (Calcola l'età in base al compleanno, ...)   |   19 Inserimento Strumenti (Inserisci il codice QR, Inserisci immagine dal percorso, ...)   |   12 Conversione Strumenti (Numeri in parole, Conversione di valuta, ...)   |   7 Unisci e dividi Strumenti (Combina righe avanzate, Celle divise, ...)   |   ... e altro ancora

Potenzia le tue competenze di Excel con Kutools per Excel e sperimenta l'efficienza come mai prima d'ora. Kutools per Excel offre oltre 300 funzionalità avanzate per aumentare la produttività e risparmiare tempo.  Fai clic qui per ottenere la funzionalità di cui hai più bisogno...

Descrizione


Office Tab porta l'interfaccia a schede in Office e semplifica notevolmente il tuo lavoro

  • Abilita la modifica e la lettura a schede in Word, Excel, PowerPoint, Publisher, Access, Visio e Project.
  • Apri e crea più documenti in nuove schede della stessa finestra, piuttosto che in nuove finestre.
  • Aumenta la produttività del 50% e riduce ogni giorno centinaia di clic del mouse!
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