Your post is short on detail so this is just an example of code for a worksheet that will change font color on cell rewrites for the range A1:A10 of the worksheet. I used red and black to alternate on rewrites. You can change the colors and the range to meet your needs. Rewrites can be by manual typing or by pasting to one or more cells in the target range.Hello Guys,
Using VBA how can change text color to different color after rewrite text cell?
Thank you very much for the help.
Private Sub Worksheet_Change(ByVal Target As Range)
Const color1 As Long = vbBlack
Const color2 As Long = vbRed
Dim c As Range
If Not Intersect(Target, Range("A1:A10")) Is Nothing Then 'Change range to suit
For Each c In Intersect(Target, Range("A1:A10"))
If Not IsEmpty(c) Then
If c.Font.Color = color1 Then
c.Font.Color = color2
ElseIf c.Font.Color = color2 Then
c.Font.Color = color1
End If
End If
Next c
End If
End Sub
Works perfect my friend!Your post is short on detail so this is just an example of code for a worksheet that will change font color on cell rewrites for the range A1:A10 of the worksheet. I used red and black to alternate on rewrites. You can change the colors and the range to meet your needs. Rewrites can be by manual typing or by pasting to one or more cells in the target range.
VBA Code:Private Sub Worksheet_Change(ByVal Target As Range) Const color1 As Long = vbBlack Const color2 As Long = vbRed Dim c As Range If Not Intersect(Target, Range("A1:A10")) Is Nothing Then 'Change range to suit For Each c In Intersect(Target, Range("A1:A10")) If Not IsEmpty(c) Then If c.Font.Color = color1 Then c.Font.Color = color2 ElseIf c.Font.Color = color2 Then c.Font.Color = color1 End If End If Next c End If End Sub
You are welcome - thanks for the reply.Works perfect my friend!
Just one improvement detail - after change it to colour red how can turn into format bold text at the same time (only in red colour not in black)?
Thanks again. ??
Private Sub Worksheet_Change(ByVal Target As Range)
Const color1 As Long = vbBlack
Const color2 As Long = vbRed
Dim c As Range
If Not Intersect(Target, Range("A1:A10")) Is Nothing Then 'Change range to suit
For Each c In Intersect(Target, Range("A1:A10"))
If Not IsEmpty(c) Then
If c.Font.Color = color1 Then
With c.Font
.Color = color2
.Bold = True
End With
ElseIf c.Font.Color = color2 Then
With c.Font
.Color = color1
.Bold = False
End With
End If
End If
Next c
End If
End Sub
Works Percfectly.You are welcome - thanks for the reply.
For your new request, replace the code I gave you with this revised version.
VBA Code:Private Sub Worksheet_Change(ByVal Target As Range) Const color1 As Long = vbBlack Const color2 As Long = vbRed Dim c As Range If Not Intersect(Target, Range("A1:A10")) Is Nothing Then 'Change range to suit For Each c In Intersect(Target, Range("A1:A10")) If Not IsEmpty(c) Then If c.Font.Color = color1 Then With c.Font .Color = color2 .Bold = True End With ElseIf c.Font.Color = color2 Then With c.Font .Color = color1 .Bold = False End With End If End If Next c End If End Sub
You are welcome - thanks for the reply.Works Percfectly.
Thank you very much.
Dear @JoeMo, ??You are welcome - thanks for the reply.
Dear @JoeMoNeed some clarification.
You want the text to be bold whenever the font color is red and not bold when color is black?
What do you want to happen when writing to A1 anytime after the second write to that cell?
Livro1.xlsx | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
D | E | F | G | H | I | J | K | |||
3 | ||||||||||
4 | N.º ITEM | PRODUT | QUANTITY | PVP | ||||||
5 | 1ST WRITE | 235 | TV | 1 | 5 € | |||||
6 | 2ND WRITE | 235 | TV | 1 | 5 € | |||||
7 | 3RD WRITE | 235 | TV | 1 | 5 | |||||
8 | ||||||||||
9 | ||||||||||
Folha3 |