Add text in red with userForm

KlaasE

New Member
Joined
Nov 4, 2019
Messages
31
Hi folks,

For a worksheet I'm making a comment form. What it does is simply add some text to a cell the user selects. What I've been unable to figure out is how I make only the added text in red, while the rest stays the same (black). Right now it add's the text from a Textbox to a cell. It seems like a simple question but I just can't find the answer yet on the forums.
The code I'm using right now:
Code:
Private Sub CommentButton_Click()
ActiveSheet.Unprotect Password:="***"
Set YourRange = Application.InputBox(Prompt:="Select Range", Type:=8)
YourRange.Select
ActiveCell.Value = ActiveCell.Value & vbNewLine & CommentTextBox.Value
ActiveSheet.Protect Password:="***"
End Sub
Thanks!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,476
Office Version
365
Platform
Windows
How about
Code:
Private Sub CommentButton_Click()
    Dim YourRange As Range
    Dim Lngth As Long
    
    ActiveSheet.Unprotect Password:="***"
    Set YourRange = Application.InputBox(Prompt:="Select Range", Type:=8)
    Lngth = Len(YourRange.Value)
    YourRange.Value = YourRange.Value & vbNewLine & CommentTextBox.Value
    YourRange.Characters(Lngth + 1).Font.Color = vbRed
    ActiveSheet.Protect Password:="***"
End Sub
 

KlaasE

New Member
Joined
Nov 4, 2019
Messages
31
Perfect, thanks!
I tried to store the whole CommentTextBox in a variable but couldn't get it working.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,476
Office Version
365
Platform
Windows
You're welcome & thanks for the feedback
 

Forum statistics

Threads
1,078,352
Messages
5,339,715
Members
399,320
Latest member
sut3k

Some videos you may like

This Week's Hot Topics

Top