I am trying to write code which changes the color of text added to a string through an input box. It works great if I only have to add colored text to the cell once, but when I try and add any more information through the input box it resets the color of all the text. What I want to do is keep the color formatting of the text currently in the cell and only change the color of the new text added by the input box if needed. Thank you for any help. Here is my current code:
Private Sub CommandButton1_Click()
Dim Str As String
Dim Cell As Range
Dim i As Integer
Dim x As Integer
Str = InputBox("Enter value to add to selection", "Enter Value")
Text_Color = MsgBox("Make Text Green?", vbYesNo, "Change Text Color")
For Each Cell In Selection
i = Len(Cell)
If Cell.Value = 0 Then
Cell.Value = Str
Else
Cell.Value = Cell.Value & ", " & Str
End If
x = Len(Cell)
If Text_Color = 6 Then
With Cell.Characters(i + 3, x - 1).Font
.Color = RGB(0, 221, 0)
End With
End If
Next Cell
End Sub
Private Sub CommandButton1_Click()
Dim Str As String
Dim Cell As Range
Dim i As Integer
Dim x As Integer
Str = InputBox("Enter value to add to selection", "Enter Value")
Text_Color = MsgBox("Make Text Green?", vbYesNo, "Change Text Color")
For Each Cell In Selection
i = Len(Cell)
If Cell.Value = 0 Then
Cell.Value = Str
Else
Cell.Value = Cell.Value & ", " & Str
End If
x = Len(Cell)
If Text_Color = 6 Then
With Cell.Characters(i + 3, x - 1).Font
.Color = RGB(0, 221, 0)
End With
End If
Next Cell
End Sub