Good afternoon,
I have been trying to get code to change the colour of some text in a cell, but to leave part black.
I attached a snip from my spreadsheet, and the code that I am running. What I am trying to achieve is "NAME" in black, "(00:00)" in Red, as per the first row, which I have done manually. The (00:00) will always have 1 space after the last letter. And to be fair, I have copied this code.
Any help would be appreciated.
I have been trying to get code to change the colour of some text in a cell, but to leave part black.
I attached a snip from my spreadsheet, and the code that I am running. What I am trying to achieve is "NAME" in black, "(00:00)" in Red, as per the first row, which I have done manually. The (00:00) will always have 1 space after the last letter. And to be fair, I have copied this code.
Any help would be appreciated.
VBA Code:
Sub ColourSomeText()
Dim P As Integer
Dim l As Integer
Dim wb As Workbook
Dim ws1 As Worksheet
Dim LastRow As Long
Dim St1 As String
Set wb = ThisWorkbook
Set ws1 = wb.Sheets("EMR")
LastRow = ws1.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To LastRow
P = InStr(Cells(i, 5).Value, " ")
l = Len(Cells(i, 5).Value)
ws1.Cells(i, 5).Characters(Start:=P + 1, Length:=8).Font.ColorIndex = 3
Next
End Sub