Sie wollen immer noch #Teile Ihrer #Zellinhalte per #VBA #formatieren? Da sind aber Texte mit einer Länge von mehr als 255 Zeichen dabei (das geht seit Version 2007) … und es #funktioniert #nicht?
Dann gehen wir das anders als gestern an – wir müssen die Positionen wegschreiben, dann die Klammern löschen und dann erst formatieren:
Sub Brackets_Bold()
Dim myCell As Range
Dim myTxt As Variant
Dim myLen As Long
Dim StartPos As Long
Dim EndPos As Long
Dim iStart(1 To 200) As Long
Dim iEnd(1 To 200) As Long
Dim I As Long
Dim nI As Long
On Error GoTo 0
For Each myCell In ActiveWorkbook.ActiveSheet.UsedRange.Cells
I = 1
EndPos = 1
StartPos = InStr(EndPos, myCell.Text, "[")
While StartPos <> 0
If Left(myCell.Formula, 1) <> "=" Then
'myCell.Characters(Start:=StartPos, Length:=1).Delete
EndPos = InStr(StartPos, myCell.Text, "]")
'StartPos = StartPos
If EndPos = 0 Then
EndPos = Len(myCell.txt)
End If
iStart(I) = StartPos
iEnd(I) = EndPos
I = I + 1
StartPos = InStr(EndPos + 1, myCell.Text, "[")
Else
StartPos = 0
End If
Wend
nI = I - 1
myCell.Replace What:="[", Replacement:="", LookAt:=xlPart, SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
myCell.Replace What:="]", Replacement:="", LookAt:=xlPart, SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
For I = 1 To nI
With myCell.Characters(Start:=iStart(I) - 2 * (I - 1), Length:=iEnd(I) - iStart(I) - 1).Font
.Bold = True
End With
Next I
Next myCell
End Sub
Puh. Lösung gefunden 🙂
Gefällt mir Wird geladen …