Ich möchte auch ein "Lehrzeichen" ;-)
26.02.2016 12:20:21
NoNet
Hi Drummer,
das "Lehrzeichen" kenne ich gar nicht, kannst Du mir das bitte mal zeigen ;-)
Spaß beiseite : Das Leerzeichen (Blank, ASCII-Zeichen 32) und das geschützte Leerzeichen (ASCII-Zeichen 160) können mit folgendem Makro gelöscht werden :
Sub Delete_Blanks_at_Start_and_End()
Dim rngCells As Range, rngC As Range
Dim arrV, lngT As Long, strA As String, lngI As Long
arrV = Array(32, 160) 'ASCII-Values
On Error Resume Next
For lngI = 1 To 2
For lngT = LBound(arrV) To UBound(arrV)
If lngI = 1 Then
Set rngC = Cells.Find(What:=Chr(arrV(lngT)) & "*", LookAt:=xlWhole, after:= _
Cells(1, 1))
Else
Set rngC = Cells.Find(What:="*" & Chr(arrV(lngT)), LookAt:=xlWhole)
End If
If Not rngC Is Nothing Then strA = rngC.Address
While Not rngC Is Nothing
If rngCells Is Nothing Then
Set rngCells = rngC
Else
Set rngCells = Union(rngCells, rngC)
End If
Set rngC = Cells.FindNext(after:=rngC)
If rngC.Address = strA Then Set rngC = Nothing
Wend
Next
Next
If rngCells Is Nothing Then
MsgBox "Keine relevanten Zellen gefunden !"
Else
'rngCells.Select
If MsgBox("Sollen jetzt folgende Zellen bereinigt werden :" & vbLf & vbLf & rngCells. _
Address, _
vbYesNo + vbQuestion, rngCells.Cells.Count & " Zellen bereinigen") = vbYes Then
For Each rngC In rngCells
rngC.Value = Trim(rngC.Value)
For lngT = LBound(arrV) To UBound(arrV)
While Left(rngC.Value, 1) = Chr(arrV(lngT))
rngC.Value = Mid(rngC.Value, 2, Len(rngC.Value) - 1)
Wend
While Right(rngC.Value, 1) = Chr(arrV(lngT))
rngC.Value = Left(rngC.Value, Len(rngC.Value) - 1)
Wend
Next
Next
MsgBox "Bereinigung beendet"
End If
End If
End Sub
Gruß, NoNet