ich google seit 1,5 Tagen im XL-Forum nach einer Lösung, um in einem String mehrere aufeinander folgende Leerzeichen durch ein einziges Semikolon zu ersetzen.
Ich bin bisher leider nicht fündig geworden.
Könnt Ihr mir helfen?
LG
Sabine
Function MehrfacheLeerZeichenErsetzen(derString As String)
Dim strTmp As String, i As Integer, strMid As String
For i = 1 To Len(derString)
strMid = Mid(derString, i, 1)
If strMid " " Then
strTmp = strTmp & strMid
ElseIf strMid = " " And Mid(derString, i + 1, 1) " " Then
If Right(strTmp, 1) ";" Then strTmp = strTmp & strMid
ElseIf Right(strTmp, 1) ";" Then strTmp = strTmp & ";"
End If
Next
MehrfacheLeerZeichenErsetzen = strTmp
End Function
Gruß
Rudi
Eine Kuh macht Muh, viele Kühe machen Mühe
A
1 Abc 123 DEF 123 GhI 4567 Qrste
2 Abc 123;DEF;123 GhI;4567;Qrste
Benutzte Formeln:
A2: =WECHSELN(WECHSELN(WECHSELN(A1; " "; ";"); "; "; ";"); ";;"; ";")
Gruß
Franz
Sub MehrfachLeerzeichenDurchEinSemicolon()
Dim strText As String, strErgebnis As String
strText = "Abc 123 DEF 123 GhI 4567 Qrste"
With Application.WorksheetFunction
strErgebnis = .Substitute(strText, " ", ";")
MsgBox strErgebnis
strErgebnis = .Substitute(strErgebnis, "; ", ";")
MsgBox strErgebnis
strErgebnis = .Substitute(strErgebnis, ";;", ";")
MsgBox strErgebnis
End With
End Sub
oder in etwas unübersichtlicherer Form geschachtelt:
Sub MehrfachLeerzeichenDurchEinSemicolon2()
Dim strText As String, strErgebnis As String
strText = "Abc 123 DEF 123 GhI 4567 Qrste"
With Application.WorksheetFunction
strErgebnis = .Substitute(.Substitute(.Substitute(strText, " ", ";"), "; ", ";"), ";;", ";" _
)
MsgBox strErgebnis
End With
End Sub
Option Explicit
Function dblspacekiller(strSpace As String)
Dim i As Integer
Dim bolSpace As Boolean
bolSpace = False
strSpace = Trim(strSpace) 'äußere Leerzeichen löschen
If Len(strSpace) > 4 Then
For i = Len(strSpace) - 2 To 2 Step -1
strSpace = Replace(strSpace, String(i, " "), ";")
Next
End If
dblspacekiller = strSpace
End Function
Führende und abschließende Leerzeichen werden einfach entfernt, ohne Erstzung durch ";".
Gruß
Harry
Option Explicit
Function dblspacekiller(strSpace As String)
Dim i As Integer
strSpace = Trim(strSpace) 'äußere Leerzeichen löschen
If Len(strSpace) >= 4 Then
For i = Len(strSpace) - 2 To 2 Step -1
strSpace = Replace(strSpace, String(i, " "), ";")
Next
End If
dblspacekiller = strSpace
End Function