Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,616
- Office Version
- 365
- 2016
- Platform
- Windows
I have this code:
The line in blue is where I would like to add code to change the font color of cell in which the replacement was made. I haven't found a solution.
If I try
I get an 'object required' error.
Rich (BB code):
Private Sub CommandButton1_Click()
Stop
Dim cdd As Range
Dim firstaddress As String
trid = ws_working.Cells(qrw, 1)
rval2 = ComboBox1.Value
openingParen = InStr(rval2, "(")
closingparen = InStr(rval2, ")")
encval = Mid(rval2, openingParen + 1, closingparen - openingParen - 1)
cell.Value = encval
cell.Font.Color = vbBlack
'check if change needs to be made elsewhere...
cntrpl = 0 'replaced values count
For Each ws10 In wb_data.Worksheets
Debug.Print "Worksheet: " & ws10.Name
If ws10.Visible = xlSheetVisible Then
cnt5 = Application.WorksheetFunction.CountIf(ws10.Columns(1), trid)
If cnt5 > 0 Then
ws10.Activate
rwmtch = Application.WorksheetFunction.Match(trid, ws10.Columns(1), 0)
With ws10.Range("H" & rwtch & ":Q" & rwtch)
Set cdd = .Find(cval2, LookIn:=xlValues)
'Debug.Print cdd.Column
If Not cdd Is Nothing Then
Debug.Print cdd.Column
svc5 = ws10.Cells(10, cdd.Column)
If IsNumeric(svc5) = True Then svc5 = "TrnService" & svc5
firstaddress = cdd.Address
Debug.Print firstaddress
Do
cdd.Value = Replace(cdd.Value, cval2, encval)
Set cdd = .FindNext(cdd)
MsgBox cval2 & " was replaced by " & encval & " in " & ws10.Name & " " & firstaddress & " (" & svc5 & ")"
'change font color of replacement value here
Loop While Not cdd Is Nothing
Else
Debug.Print cval2 & " not associated to " & trid & " in worksheet: " & ws10.Name
End If
End With
Else
Debug.Print "No match of " & trid & " in worksheet: " & ws10.Name
End If
Else
Debug.Print ws10.Name & " excluded [Hidden]"
End If
Next ws10
MsgBox "All visible worksheets checked for instances of " & cval2 & Chr(13) & cntrpl & " replacements were made." & Chr(13) & "(For RID: " & trid & " only.)"
Unload Me
'Stop
End Sub
The line in blue is where I would like to add code to change the font color of cell in which the replacement was made. I haven't found a solution.
If I try
Code:
cdd.font.color=vbgreen