deluxe_247
New Member
- Joined
- Dec 18, 2018
- Messages
- 6
I have a workbook with 2 sheets. Sheet 1 cell A1 has a (black) text sting in it. Sheet 2 has two cells I'm working with, cells A1 and B1. The text stings in Sheet 2 cells A1 and B1 are also black.
I'm trying to search the text string in Sheet 1 cell A1, see if it contains the text string from Sheet 2 cell B1, and, if it does, replace that part of the text string in Sheet 1 cell A1 with (a red text version of) the text string Sheet 2 cell A1.
There's a better way of saying that. But to be clear, I don't want to replace the entire contents of Sheet 1 cell A1, just (a red text version of) the text string from Sheet 2 cell B1.
The find replace part works great. But I can't seem to get the text string to turn red.
Any help would be greatly appreciated!
Here's the code I'm working with so far:
Sub TextReplace()
Dim Findtext As String
Dim Replacetext As String
With Sheets("Sheet1")
.Activate
Findtext = Sheets("Sheet2").Range("B1").Value
Replacetext = Sheets("Sheet2").Range("A1").Value.Font.Color = RGB(255, 0, 0)
Cells.Replace What:=Findtext, Replacement:=Replacetext, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With
End Sub
I'm trying to search the text string in Sheet 1 cell A1, see if it contains the text string from Sheet 2 cell B1, and, if it does, replace that part of the text string in Sheet 1 cell A1 with (a red text version of) the text string Sheet 2 cell A1.
There's a better way of saying that. But to be clear, I don't want to replace the entire contents of Sheet 1 cell A1, just (a red text version of) the text string from Sheet 2 cell B1.
The find replace part works great. But I can't seem to get the text string to turn red.
Any help would be greatly appreciated!
Here's the code I'm working with so far:
Sub TextReplace()
Dim Findtext As String
Dim Replacetext As String
With Sheets("Sheet1")
.Activate
Findtext = Sheets("Sheet2").Range("B1").Value
Replacetext = Sheets("Sheet2").Range("A1").Value.Font.Color = RGB(255, 0, 0)
Cells.Replace What:=Findtext, Replacement:=Replacetext, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End With
End Sub