Good All below code to format individual character it works but does not work with last format so I added 1 total cell content (Len(TXT)+1), but not useful
thanks
thanks
Code:
Public Sub TXTFrmt()
Dim WB As Workbook: Set WB = ThisWorkbook
Dim WS As Worksheet: Set WS = ActiveSheet ' WB.Worksheets(1) '<<<<<<< Name it as you like
Dim Rng As Range, TblRng As Range
Dim Bold As Boolean, Italic As Boolean
With WS
Set TblRng = .Range("A1")
For Each Rng In TblRng
With Rng
'''''''''''''''''for Example'''''''''''''''''''
.Value = "ABCDEFGH" '
With .Characters(Start:=2, Length:=1).Font '
.FontStyle = "Bold" '
End With '
With .Characters(Start:=4, Length:=2).Font '
.FontStyle = "Bold Italic" '
End With '
With .Characters(Start:=7, Length:=1).Font '
.FontStyle = "Italic" '
End With '
'''''''''''''''''''''''''''''''''''''''''''''''
TXT = .Text
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
For n = 1 To Len(TXT) [COLOR=#0000ff][B]+ 1[/B][/COLOR] '<<<<<
With .Characters(Start:=n, Length:=1)
T = Mid(TXT, n, 1)
With .Font 'Characters Font
B = "": EB = ""
I = "": EI = ""
If .Bold = Bold And .Italic = Italic Then
M = M & T
Bold = .Bold: Italic = .Italic ' Rest
ElseIf .Bold <> Bold Or .Italic <> Italic Then 'here foramt if Bold or Italic
If Bold = True Then B = "<B>": EB = "</B>"
If Italic = True Then I = "<I>": EI = "</I>"
M = B & I & M & EI & EB
RngTXT = RngTXT & M 'Format similarities
[COLOR=#0000ff] MsgBox M '<<[/COLOR]
M = "": M = T '<<<<< clear old and gather new Changes
Bold = .Bold: Italic = .Italic ' Rest
End If
End With 'Characters Font
End With
Next n
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End With
Next
End With
[COLOR=#0000ff] MsgBox "Final :" & RngTXT '<<[/COLOR]
End Sub