Partial colour text with Excel Formula?

kgkev

Well-known Member
Joined
Jun 24, 2008
Messages
1,285
Office Version
  1. 365
Platform
  1. Windows
I am dragging some data from various sheets and presenting it on a single line
Code:
=IFERROR(VLOOKUP(H5&"|"&B5&"|"&D5,comments!$A:$B,2,FALSE)&" ("&TEXT(((VLOOKUP(H5&"|"&B5&"|"&D5,comments!$A:$D,4,FALSE))),"dd/mm/yyyy")&")",Z5)&IF(AE5<>""," //-// Picking info: "&TEXT(AE5,"dd/mm/yy")&" "&AF5,"")


If the last part contains some text I would like it to be coloured red

Code:
=IFERROR(VLOOKUP(H5&"|"&B5&"|"&D5,comments!$A:$B,2,FALSE)&" ("&TEXT(((VLOOKUP(H5&"|"&B5&"|"&D5,comments!$A:$D,4,FALSE))),"dd/mm/yyyy")&")",Z5)[COLOR=#ff0000]&IF(AE5<>""," //-// Picking info: "&TEXT(AE5,"dd/mm/yy")&" "&AF5,"")[/COLOR]

is that possible?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Not that I'm aware of without the use of VBA.
 
Last edited:
Upvote 0
Hi,

To me this is only possible with VBA. Select all cells that have your formula and run this macro

Code:
Sub RedToEndOfCell()
On Error Resume Next
 For Each cell In Selection
    If InStr(cell.Value, " //-// Picking info:") = 0 Then
      Else
        With cell.Characters(Start:=InStr(cell.Value, " //-// Picking info:"), Length:=Len(cell.Value) + 1 - InStr(cell.Value, " //-// Picking info:")).Font
        .Color = -16776961
        End With
    End If
 Next cell
End Sub
 
Last edited:
Upvote 0
it doesn't seem to work for me.
I have slightly modified it, and it still lands on the With statement in the correct place, but the colour is not updated.

Code:
Sub colourred()



    For Each cell In Range("M5", Range("B56000").End(xlUp))
        If InStr(cell.Value, " //-// Picking info:") = 0 Then
        Else
            With cell.Characters(Start:=InStr(cell.Value, " //-// Picking info:"), Length:=Len(cell.Value) + 1 - InStr(cell.Value, " //-// Picking info:")).Font
                .Color = -16776961
            End With
        End If
    Next cell
End Sub

any ideas?
 
Upvote 0
You can't colour part of the result of a formula. You'd have to replace the formula with its value and then colour the relevant section(s).
 
Upvote 0
Thanks for the heads up Rory,

I have moved the formula to end of the sheet and added a pastespecial back to "M"

unfortunately its still not working.

Code:
Sub colourred()

    Range("AG5", Range("AG56000").End(xlUp)).Copy
    Range("M5").PasteSpecial xlPasteValues
    For Each cell In Range("M5", Range("B56000").End(xlUp))
        If InStr(cell.Value, " //-// Picking info:") = 0 Then
        Else
            With cell.Characters(Start:=InStr(cell.Value, " //-// Picking info:"), Length:=Len(cell.Value) + 1 - InStr(cell.Value, " //-// Picking info:")).Font
                .Color = RED
            End With
        End If
    Next cell
End Sub
 
Upvote 0
Have you declared RED somewhere?
 
Upvote 0
Also try
Code:
For Each cell In Range("M5", Range("[COLOR=#ff0000]M[/COLOR]56000").End(xlUp))
 
Last edited:
Upvote 0
Code:
Sub ColorRed()
  Const sWhat       As String = "//-// Picking info:"
  Dim rFind         As Range
  Dim iPos          As Long
  Dim sAdr          As String

  Range("AG5", Range("AG56000").End(xlUp)).Copy
  Range("M5").PasteSpecial Paste:=xlPasteValues

  With Range("M:M")
    Set rFind = .Find(What:=sWhat, LookIn:=xlValues, LookAt:=xlPart)

    If Not rFind Is Nothing Then
      sAdr = rFind.Address
      Do
        rFind.Select  ' remove when you're happy
        iPos = InStr(rFind.Value, sWhat)
        rFind.Characters(Start:=iPos, Length:=100).Font.Color = vbRed
        Set rFind = .FindNext(rFind)
      Loop While rFind.Address <> sAdr
    End If
  End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,974
Messages
6,122,536
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top