Aquí hay una solución usando VBA.
Usar:
Presione Alt
+ F11
- Copie el código enThisWorkbook
Puede ejecutar el código desde: MS Excel - View
pestaña - Macros
(tecla de acceso rápido: Alt
+ F8
)
o puede asignarle un botón.
La macro se aplicará en cada celda utilizada de forma predeterminada. Si necesita esta modificación, solo deje un comentario y actualizaré la respuesta con las modificaciones solicitadas.
Sub remove_spaces()
Dim actives As String
Dim c As Range
Dim myStr As String
Dim myArray() As String
Dim wordsc As String
Dim wcount As Integer
Dim newStr As String
actives = ActiveSheet.Name
For Each c In Sheets(actives).UsedRange.Cells
If c <> "" Then
wordsc = c
wcount = WordCount(wordsc)
ReDim myArray(wcount)
myStr = c
myArray = Split(myStr, " ")
c = ""
newStr = myArray(0)
For i = 1 To wcount - 1
MsgBox myArray(i)
If Len(myArray(i - 1)) = 1 And Len(myArray(i)) = 1 Then
newStr = newStr & myArray(i)
Else
newStr = newStr & " " & myArray(i)
End If
c = newStr
Next i
End If
Next c
End Sub
Function WordCount(fullText As String) As Long
Dim words() As String
Dim firstLetter As String
Dim i As Long
words = Split(fullText)
For i = LBound(words) To UBound(words)
firstLetter = UCase$(Left$(words(i), 1))
' if it's alphabetic, +1 word
If firstLetter Like "[A-Za-z]" Then
WordCount = WordCount + 1
End If
Next i
End Function