Monday, 5 October 2015

Extract text Based on Font Color from a Cell in Excel

'VBA: Extract text based on font color

Function GetColorText(rng As Range) As String


Dim x As String

Dim y As String
Dim i As Long

y = rng.Text

For i = 1 To VBA.Len(y)
If rng.Characters(i, 1).Font.Color = vbRed Then
x = x & VBA.Mid(y, i, 1)
End If
Next

GetColorText = x


End Function


 Type this Formula =GetColorText(A1) (A1 indicates the cell you want to extract text from), press Enter key to get the needed text, then drag autofill handle to fill the formula to the range you want.



Now you can see all red text are extracted.


>