Consejo: Otros idiomas son traducidos por Google. Puedes visitar el English versión de este enlace.
Iniciar sesión
x
or
x
x
Suscríbete
x

or

¿Cómo eliminar caracteres duplicados o palabras en la cadena de una celda?

Supongamos que hay caracteres o palabras duplicados en cada celda, y desea eliminar los duplicados y dejar solo caracteres o palabras únicos. ¿Cómo podrías resolver este problema en Excel?

Eliminar los caracteres duplicados de la cadena de texto con la función definida por el usuario

Eliminar las palabras duplicadas separadas por signos de puntuación con la función definida por el usuario


Seleccione valores duplicados en una columna y luego elimínelos de una vez:

Con Kutools for Excel, Seleccione celdas duplicadas y exclusivas función, puede seleccionar y resaltar rápidamente los valores duplicados o únicos de un rango, y luego puede eliminarlos o formatearlos según lo necesite.

doc elimina ambos duplicados 15 15


flecha azul burbuja derecha Eliminar los caracteres duplicados de la cadena de texto con la función definida por el usuario


Si tiene una lista de cadenas de texto, ahora debe eliminar los caracteres duplicados como se muestra a continuación. Aquí, puedo hablar sobre un código VBA para manejarlo.

doc-remove-duplicate-characters-1

1. Mantenga presionado el ALT + F11 teclas para abrir el Ventana de Microsoft Visual Basic para Aplicaciones.

2. Hacer clic recuadro > Móduloy pegue el siguiente código en Ventana de módulo.

Código de VBA: elimina los caracteres duplicados de una cadena de texto en una celda

Function RemoveDupes1(pWorkRng As Range) As String
'Updateby20140924
Dim xValue As String
Dim xChar As String
Dim xOutValue As String
Set xDic = CreateObject("Scripting.Dictionary")
xValue = pWorkRng.Value
For i = 1 To VBA.Len(xValue)
    xChar = VBA.Mid(xValue, i, 1)
    If xDic.Exists(xChar) Then
    Else
        xDic(xChar) = ""
        xOutValue = xOutValue & xChar
    End If
Next
RemoveDupes1 = xOutValue
End Function

3. Luego guarde y cierre este código, regrese a la hoja de trabajo e ingrese esta fórmula = removedupes1 (A2) (A2 es la celda de datos de la que desea eliminar los duplicados) en una celda en blanco además de sus datos, vea la captura de pantalla:

doc-remove-duplicate-characters-1

4. Y luego arrastre el controlador de relleno a las celdas de rango en las que desea aplicar esta fórmula, todos los caracteres duplicados se han eliminado de cada celda de inmediato.

doc-remove-duplicate-characters-1


flecha azul burbuja derecha Eliminar las palabras duplicadas separadas por signos de puntuación con la función definida por el usuario

Si hay algunas palabras que están separadas por ciertos signos de puntuación en una celda, también puede eliminar las palabras duplicadas como desee. Por favor haz los siguientes pasos:

1. Mantenga pulsado el botón ALT + F11 teclas para abrir el Ventana de Microsoft Visual Basic para Aplicaciones.

2. Hacer clic recuadro > Móduloy pegue el siguiente código en Ventana de módulo.

Código VBA: eliminar las palabras duplicadas separadas por la puntuación de una celda

Function RemoveDupes2(txt As String, Optional delim As String = " ") As String
    Dim x
    'Updateby20140924
    With CreateObject("Scripting.Dictionary")
        .CompareMode = vbTextCompare
        For Each x In Split(txt, delim)
            If Trim(x) <> "" And Not .exists(Trim(x)) Then .Add Trim(x), Nothing
        Next
        If .Count > 0 Then RemoveDupes2 = Join(.keys, delim)
    End With
End Function

3. A continuación, guarde y cierre este código, regrese a la hoja de trabajo e ingrese esta fórmula = RemoveDupes2 (A2, ",") en una celda en blanco al lado de tus datos, mira la captura de pantalla:

doc-remove-duplicate-characters-1

4. Luego copie la fórmula en las celdas que necesita, y todas las palabras duplicadas se han eliminado de cada celda. Ver captura de pantalla:

doc-remove-duplicate-characters-1

Nota: En la fórmula anterior, A2 indica la celda que desea usar, y la coma (,) representa el signo de puntuación que separa las palabras en una celda, puede cambiarlo a cualquier otra puntuación que necesite.


Kutools for Excel: la mejor herramienta de productividad de Office aumenta su productividad en un 80%

  • Super Formula Bar (edite fácilmente varias líneas de texto y fórmula); Diseño de lectura (lee y edita fácilmente un gran número de celdas); Pegar en rango filtrado...
  • Combinar celdas / filas / columnas y mantener datos; Contenido de celdas divididas; Combinar filas duplicadas y suma / promedio... Prevenir células duplicadas; Comparar rangos...
  • Seleccione Duplicado o Único Filas; Seleccionar filas en blanco (todas las celdas están vacías); Super Find y Fuzzy Find en muchos libros de trabajo; Selección aleatoria ...
  • Copia exacta Celdas múltiples sin cambiar la referencia de fórmula; Crear referencias automáticamente a múltiples hojas; Insertar viñetas, Casillas de verificación y más ...
  • Fórmulas favoritas e insertadas rápidamente, Gamas, cuadros y cuadros; Cifrar celdas con contraseña Crear una lista de correo y enviar correos electrónicos ...
  • Extracto del texto, Agregar texto, Eliminar por posición, Eliminar espacio; Crear e imprimir subtotales de paginación; Convertir entre contenido de celdas y comentarios...
  • Súper filtro (guardar y aplicar esquemas de filtro a otras hojas); Clasificación avanzada por mes / semana / día, frecuencia y más; Filtro especial por negrita, cursiva ...
  • Combinar libros de trabajo y hojas de trabajo; Combinar tablas basadas en columnas clave; Dividir datos en varias hojas; Conversión por lotes xls, xlsx y PDF...
  • Más de potentes funciones de 300. Funciona con Office 2007-2019 y 365. Soporta todos los idiomas. Fácil despliegue en compañía. Funciones completas de prueba gratuita de 60-day.
pestaña kte 201905

Office Tab lleva la interfaz con pestañas a Office y hace que su trabajo sea mucho más fácil

  • Habilitar la edición y lectura con pestañas en Word, Excel, PowerPoint, Editor, Acceso, Visio y Proyecto.
  • Abra y cree varios documentos en nuevas pestañas de la misma ventana, en lugar de en nuevas ventanas.
  • ¡Aumenta tu productividad en un 50% y reduce cientos de clics de ratón por ti todos los días!
fondo officetab
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    vinay · 19 hours ago
    thank you so much for information
    the VBA code RemoveDupes2
    i need the output as below
    Code,post,code,guest,code,location ----> post,guest,location


    could you please suggest. I really appreciate your help
  • To post as a guest, your comment is unpublished.
    jenny · 6 days ago
    How can I remove the word dealer code in every word in each cell and just leave the number.
    Like the following:
    DEALER CODE A123
    DEALER CODE B456
    DEALER CODE C789
    DEALER CODE D012

    Result needed is:
    A123
    B456
    C789
    D012
    • To post as a guest, your comment is unpublished.
      skyyang · 3 hours ago
      Hi, jenny,
      To remove the first x characters from a cell, please apply the below formula:
      =RIGHT(A1, LEN(A1)-12)

      Please try, hope it can help you!
  • To post as a guest, your comment is unpublished.
    alongkorn · 11 days ago
    Disturbing Excel formula


    If column A1 = R10, R11, R12, R13, R14, R15, R16, R17


    And column B1 = R10, R11, R19, R13, R14, R18, R20, R17


    Want the column C1 to find the difference


    Will get column C1 = R12, R19, R15, R16, R18, R20


    How to use the formula?
  • To post as a guest, your comment is unpublished.
    Rocio · 7 months ago
    Hi, what should I do if I want to delete duplicated words within on cell? For example, Ana Garcia Lopes Garcia -> Ana Garcia Lopes
    • To post as a guest, your comment is unpublished.
      skyyang · 7 months ago
      Hello, Rocio,
      To remove the duplicate words within a cell, you should apply the User Defined Function of the second method in this article,
      Remove duplicate words separated by punctuation with User Defined Function

      and then apply this formula:=RemoveDupes2(A2," ").
      Please try it, hope it can help you!
      • To post as a guest, your comment is unpublished.
        Rocio · 7 months ago
        Thanks! but what will happen if i do not have punctuation within the cell? for example: Apple Book Pencil Book and I want to remove the duplicated word in this case Book and just obtain Apple Book Pencil
        • To post as a guest, your comment is unpublished.
          skyyang · 7 months ago
          Hi,
          If your cell value is separated by space, after pasting the above code, you just need to replace the comma with space as follows:
          Replace this formula:=RemoveDupes2(A2,",") with =RemoveDupes2(A2," ")
  • To post as a guest, your comment is unpublished.
    Bill Davis · 8 months ago
    I have been using the VBA code: Remove duplicate words separated by punctuation of a cell RemoveDupes2 logic for some time now and I recently had my machine upgraded to O365 and when running this same process, I get an error on my cell. Instead of returning the values I expect, I am getting the #Value! error in the cell.

    I'm not too savy on writing formulas or using the VB logic, so not sure where to start, any guidance would be helpful.
  • To post as a guest, your comment is unpublished.
    NeedExcelHelp · 11 months ago
    What about removing duplicate addresses. If I have a cell that says "123 Address St. 123 Address St." How can I select only the first address when I have many cells with different addresses in each of them?
  • To post as a guest, your comment is unpublished.
    Suraj Singh · 11 months ago
    Can we removed the duplicate from in single cell tax . like as per below tax the highlighted tax is duplicate.

    C2/1104, SUMMER PALM SECTOR 86 C2/1104, SUMMER PALM FARIDABAD HARYANA India
  • To post as a guest, your comment is unpublished.
    Angshuman Pradhan · 1 years ago
    how to save =RemoveDupes2 this formula in excel 2007
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hello, Pradhan,
      To save this formula for using next time, you should save the workbook as Excel Macro-Enabled Workbook file format.
      Please try it, hope it can help you!
  • To post as a guest, your comment is unpublished.
    Alonso · 1 years ago
    Thanks for the code.

    Can you please help me? I am using the macro function to remove words separated by punctuation of a cell, however my data is not words is actually phrases. Like instead of "KTE, KTO, KTW, KTO" is actually short descriptions like "prepare a bill, review my emails, update the contracts, review my emails".

    Would it be possible to update the VBA to remove duplicated phrases instead of words?

    Many thanks, this will be actually very helpful.
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hi, Alonso,
      To remove duplicate phrase, the following User Defined Function may help you, please try it.

      Function RemoveDuplicateValue(xStr As String, xDelim As String) As String
      Dim xValue
      If (Len(xDelim) > 0) And (Len(Trim(xStr)) > 0) Then
      With CreateObject("Scripting.Dictionary")
      For Each xValue In Split(xStr, xDelim)
      If Trim(xValue) <> "" And Not .exists(Trim(xValue)) Then .Add Trim(xValue), Nothing
      Next
      If .Count > 0 Then RemoveDuplicateValue = Join(.keys, xDelim)
      End With
      Else
      RemoveDuplicateValue = xStr
      End If
      End Function

      Then apply this formula: =RemoveDuplicateValue(A2,","), change the separator , to your own.
      • To post as a guest, your comment is unpublished.
        Michael Wentzell · 11 months ago
        Hello skyyang,



        I am hoping to get some help with the following cell:

        PR-PUERTO RICO; US-UNITED STATES; US-UNITED STATES

        I need the duplicate US-UNITED STATES removed as my upload tool will not allow for duplicates.



        I used the above VBA and replaced my formula deliminator with ";". Is the hyphen causing this to have an issue? It returns #NAME? whenever I run the formula. I am new to macros/VBA but I made sure the file was saved as a Macro Enabled file. I really tried to follow these to the T.


        Thank you for all of this already great information as it has helped with another project I had to complete as well and anything additional is greatly appreciated.
        • To post as a guest, your comment is unpublished.
          skyyang · 11 months ago
          Hi, Michael,
          Do you mean to remove all duplicate phrases from a cell, and only leave the unique ones?
          Look forward to your reply!
          • To post as a guest, your comment is unpublished.
            Michael Wentzell · 11 months ago
            This is the output I am looking for:

            Current: PR-PUERTO RICO; US-UNITED STATES; US-UNITED STATES
            Desired: PR-PUERTO RICO; US-UNITED STATES

            Hope this makes sense and thank you very much for the quick reply.
            • To post as a guest, your comment is unpublished.
              skyyang · 11 months ago
              Hi, Michael,
              You just need to apply the below code, and then use this formula: =RemoveDuplicateValue(A2,";"). Please try, hope it can help you!

              Function RemoveDuplicateValue(xStr As String, xDelim As String) As String
              Dim xValue
              If (Len(xDelim) > 0) And (Len(Trim(xStr)) > 0) Then
              With CreateObject("Scripting.Dictionary")
              For Each xValue In Split(xStr, xDelim)
              If Trim(xValue) <> "" And Not .exists(Trim(xValue)) Then .Add Trim(xValue), Nothing
              Next
              If .Count > 0 Then RemoveDuplicateValue = Join(.keys, xDelim)
              End With
              Else
              RemoveDuplicateValue = xStr
              End If
              End Function
  • To post as a guest, your comment is unpublished.
    Imran Rtul · 1 years ago
    thanks a lot, it helps me more. But I want some specific more for my dataset.
    I have two Columns data. ID and Info. In Info Column, per cell project-id like "Kant-, Udp-, Akr- etc" are repeated. For my dataset the project_id is more than 15 and It fixed. So I want to delete the repeated_id from cell but keep the first one.
    Examle: Kant-526 (0.0287),Kant-527 (0.0113),Kant-528 (0.0262) /// Kant-526 (0.0287),527 (0.0113),528 (0.0262),
    Kant-543 (0.0685),Kant-544 (0.0685),Udp-097 (0.0141) /// Kant-543 (0.0685),544 (0.0685),Udp-097 (0.0141)

    Sample image is attached here. Is there any solution for this.
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hello, Imran,
      Sorry for not solving your problem, if anyone has the good idea, please comment here.
      Thank you!
      • To post as a guest, your comment is unpublished.
        Imran Rtul · 1 years ago
        I have got a solution by my own. I have used SUBSTITUTE formula here, but it is too large for my data. so repeat it two or three times for getting the proper result.

        =SUBSTITUTE(SUBSTITUTE("Kant-","",2), ("Kant-","",2)
        Here, 1st 2 for second Kant- replacement and for next every Kant- removing just add ("Kant-","",2) extra. Its working for me. But I prefer a good VBA.
  • To post as a guest, your comment is unpublished.
    Kiran · 1 years ago
    How to remove matched string duplicates...can u pls tell me


    Regards,
    Kiran
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hello, Kiran,
      Can you give an example of your problem? Or you can insert an attachment image.
      Looking forward to your reply!
  • To post as a guest, your comment is unpublished.
    Meharban singh pal · 2 years ago
    can we find out position of 1st Lower case letter


    Exam - RAMSHsJHSAhsjDDD ------I want to know position of 1st small letter by formula = s
    • To post as a guest, your comment is unpublished.
      skyyang · 1 years ago
      Hello, Meharban,
      You can apply the following array formula to get the position of the first lower case letter:
      =MATCH(1,IF(ABS(CODE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))-109.5)<=12.5,1),0)
      Please remember to press Ctrl + Shift + Enter keys together.


      Hope it can help you ,thank you!
      • To post as a guest, your comment is unpublished.
        Meharban singh pal · 1 years ago
        Hi skyyang

        it's working properly .....
        actually i wanted same thing..

        many thanks !!


        Meharban singh pal
  • To post as a guest, your comment is unpublished.
    Hanuman Singh · 2 years ago
    I have data like 1. show below in a single cell and I want to like 2.
    1. ZERPUR,MAHENDRAGARH, HARYANA-123029, 30771237, 8813073653, ZERPUR(16),MAHENDRAGARH, HARYANA-123029, 30771237, 8813073653
    I need this like :-
    ZERPUR,MAHENDRAGARH, HARYANA-123029, 30771237, 8813073653

    Thanks & Regards
    Hanuman Singh
    9034509168
  • To post as a guest, your comment is unpublished.
    Mitch L · 2 years ago
    Thanks for this code - it saved me a ton of time.
  • To post as a guest, your comment is unpublished.
    Simon Alexander · 2 years ago
    This is an awesome and simple solution to finding duplicate phrases within a single cell, much easier than some of the long-winded macro solutions I found while looking for an answer to my problem, thank you!
  • To post as a guest, your comment is unpublished.
    Archana Nahak · 2 years ago
    This is very helpful . I have tried it and it works for me as excepted.
    Excellent !!!!
  • To post as a guest, your comment is unpublished.
    Alastair · 2 years ago
    Just like to save thank you so much for this guide, saved me a lot of work! :)
  • To post as a guest, your comment is unpublished.
    Eka Sari · 2 years ago
    Is it possible to adjust the function if there is a certain word I want to keep duplicated while the rest are not duplicated?
  • To post as a guest, your comment is unpublished.
    Joni · 2 years ago
    Hy dude i need your help. What should i do if iwant extract the duplicate?
    In
    A1 (asdfghjiklkk)
    So k is duplicated character
    I want A2 (k) what should i do?
  • To post as a guest, your comment is unpublished.
    Suresh · 2 years ago
    Awesome, Thank you!.....
  • To post as a guest, your comment is unpublished.
    Leila · 3 years ago
    BRILLIANT
    thank you! thank you! thank you!
  • To post as a guest, your comment is unpublished.
    Rana · 3 years ago
    Hello, please I need your help, i tried your code but it didnt work, maybe because I have numbers
    I have duplicate telephone numbers separated by commas
    Please tell me what to do

    Thanks
  • To post as a guest, your comment is unpublished.
    Charlie Keyloe · 3 years ago
    Your advice is amazing! I sorted 58,400 records in about 2 minutes and saved one week (or more) of work. My duplicates were a bit harder turning this example " V&O Liquid Fuel Lantern 13-1/2in blk fuel lantern " into this " V&O Liquid Fuel Lantern 13-1/2in blk " thank you.
  • To post as a guest, your comment is unpublished.
    john galt · 4 years ago
    is this thread still alive? I would greatly appreciate some insight with this VBA function..
    my questions has to do with the code, where if at all do i need to instruct it to find the specific punctuation as the delimiter.. if I were to use "@" as the punctuation?
  • To post as a guest, your comment is unpublished.
    Lisa Robinson · 4 years ago
    I tried your solution "Remove duplicate words separated by punctuation with User Defined Function" and it works great for multiple words in a cell BUT doesn't completely solve my problem. I have one cell that has multiple values and want to compare against another cell with multiple values and then have it remove the duplicates that exist between the two cells. Is there a way to do that?
  • To post as a guest, your comment is unpublished.
    milworker · 4 years ago
    And I combined RemoveDupes with ConCat (the VBA goodness, not CON(I-SUCK-BECAUSE-I'M-MICROSOFT)CATENATE) into this:

    =RemoveDupes(ConCat(",",G495:G502),",") so it pulled my cells in and then wiped all of the dupes out. Thanks for the RemoveDupes, here's ConCat:

    Function ConCat(Delimiter As Variant, ParamArray CellRanges() As Variant) As String

    Dim Cell As Range, Area As Variant

    If IsMissing(Delimiter) Then Delimiter = ""

    For Each Area In CellRanges
    If TypeName(Area) = "Range" Then
    For Each Cell In Area
    If Len(Cell.Value) Then ConCat = ConCat & Delimiter & Cell.Value
    Next
    Else
    ConCat = ConCat & Delimiter & Area
    End If
    Next

    ConCat = Mid(ConCat, Len(Delimiter) + 1)
    End Function
  • To post as a guest, your comment is unpublished.
    milworker · 4 years ago
    Nevermind, I'm dumb. Because I only wanted words pulled I renamed the module RemoveDupes, but didn't change the RemoveDupes later in the code. Fixed, smacking self with hammer....
  • To post as a guest, your comment is unpublished.
    milworker · 4 years ago
    Still broke... doesn't actually show anything. Here's my cell data:

    27000,Basic,Products,Materials,From,Wood,Stone,Earthen,Raw,Materials,27100,Basic,Forest,Products,General,27110,Basic,Forest,Products,Sawmill,Products,27120,Basic,Forest,Products,Wood,Pulp,27200,Glass

    Clearly have some dupes there. Leaves the cell blank. Thoughts?