Código para concatenar celdas mediante comas en excel

Este es el código que uso para concatenar celdas que funciona a la perfección pero me gustaría que al coger el contenido de la penúltima celda no le ponga un ", " sino un "y ". Si me pueden ayudar, gracias.

Function CONCATENARCELDAS(rango As Range)

For Each celda In rango.Cells
If celda.Value <> "" Then
resultado = resultado & ", " & celda.Value
End If
Next celda
resultado = Right(resultado, Len(resultado) - 2)
CONCATENARCELDAS = resultado

End Function

Respuesta
1

Por si deseas ahondar en el tema de trabajo con string o texto fíjate en los siguientes links

https://youtu.be/gw69AFiineY

https://youtu.be/xrnRXULC6QE

https://youtu.be/XLxuc-k8-FM

https://youtu.be/YIdGYKz_f5Q

https://youtu.be/34mzRbaPUfU

1 respuesta más de otro experto

Respuesta
2

Te anexo el código actualizado

Function CONCATENARCELDAS(rango As Range)
    For Each celda In rango.Cells
        If celda.Value <> "" Then
            resultado = resultado & ", " & celda.Value
        End If
    Next celda
    resultado = Right(resultado, Len(resultado) - 2)
    ult = InStrRev(resultado, ",")
    If ult > 1 Then
        resultado = Left(resultado, ult - 1) & " y" & Mid(resultado, ult + 1)
    End If
    CONCATENARCELDAS = resultado
End Function

'.[Sal u dos. Dante Amor. No olvides valorar la respuesta. 
'.[Avísame cualquier duda
La pregunta no admite más respuestas

Más respuestas relacionadas