You are on page 1of 13

How To Extract Text Based On Font Color From A

Cell In Excel?
If you have a data list with some red text in each cell in Excel as shown as below
screenshot, and do you know how to extract the red text only? Now I will introduce a
quick way to solve the puzzle that extracts text based on the font color from a cell in
Excel.

Extract text based on font color from each cell

Recommended Productivity Tools

Office Tab: Bring handy tabs to Excel and other Office software, just like
Chrome, Firefox and new Internet Explorer.Try now
Kutools for Excel: 200 new features for Excel, make Excel much easy and
powerful, increase productivity immediately.Try now

Extract Text Based On Font Color From Each Cell

Amazing! Using Tabs In Excel Like Firefox, Chrome, Internet Explore 10!
In Excel, you only can use the defined function to extract the text based on font
color.

1. Press Alt + F11 keys together to open the Microsoft Visual Basic for
Applications window.

2. Click Insert > Module and copy the follow VBA code to the popped out window.

VBA: Extract text based on font color

1
2 Function GetColorText(pRange As Range) As String
3 'Updateby20141105
4 Dim xOut As String
Dim xValue As String
5 Dim i As Long
6 xValue = pRange.Text
7
8 For i = 1 To VBA.Len(xValue)
9
10 If pRange.Characters(i, 1).Font.Color = vbRed Then
xOut = xOut & VBA.Mid(xValue, i, 1)
11 End If
12
13 Next
14
15 GetColorText = xOut
16 End Function
17

3. Then save and close the dialog, and select a blank cell next to the data list, 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.

Tip: In the above VBA code, if you need to extract the black text from cells, you
can change the color name Color = vbRed to Color=vbBlack.
How To Count / Sum Cells Based On The Font
Colors In Excel?

How could you get the number of cells or sum all the cells which contain a particular
font color in Excel? For example, I have a range of data in a worksheet as following
screenshot shown, and now I want to respectively count or sum the cells that have a
red, blue and black font color.In Excel, there is no direct formula to deal with this
task, here, i will talk about some tricks for soling this job.

Count or sum cells based on font colors with User Defined Function

Count or sum cells based on font color with Kutools for Excel

Count or sum cells based on background color with Kutools for Excel

Count / Sum cell values based on background, font, conditional


formatting color:

Kutools for Excel's Count by Color feature can help you to get some
calculations based on font, background or conditional formatting color as you
need.
Kutools for Excel: with more than 200 handy Excel add-ins, free to try with
no limitation in 60 days. Download and free trial Now!

Count Or Sum Cells Based On Font Colors With User Defined


Function

Amazing! Using Tabs In Excel Like Firefox, Chrome, Internet Explore 10!

Count cells based on font colors:


To calculate the number of cells with specific font colors, please do as these:

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for
Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Count cells based on font colors:

1
Public Function CountColour(pRange1 As Range, pRange2 As Range) As Double
2
'Update 20140210
3 Application.Volatile

4 Dim rng As Range

5 For Each rng In pRange1

6 If rng.Font.Color = pRange2.Font.Color Then

7 CountColour = CountColour + 1

End If
8
Next
9
End Function
10

3. Then save this code and go back to the worksheet, and then enter this formula
in to a blank cell =CountColour(A1:D8,A1) , see screenshot:
Note: In the above formula, A1:D8 is the range that you want to use and A1 is the
cell with a particular font color that you want to count.

4. After typing the formula, press Enter key, and you will get the number of cells
with red font colors. If you want to count other font colored cells, please repeatedly
enter the formula as possible as you need. You will get the following results:

Sum cells based on font colors:

To sum cells based on font colors, the following User Defined Function can help
you.

1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for
Applications window.

2. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Sum cells based on font colors:

Public Function SumByColor(pRange1 As Range, pRange2 As Range) As Double


1
'Update 20140210
2
Application.Volatile
3
Dim rng As Range
4
Dim xTotal As Double
5
xTotal = 0
6 For Each rng In pRange1
7 If rng.Font.Color = pRange2.Font.Color Then

8 xTotal = xTotal + rng.Value

End If
9
Next
10
SumByColor = xTotal
11
End Function
12

13

3. Then save this code and return to the original worksheet, and then enter this
formula =SumByColor(A1:D8,A1) into a blank cell, see screenshot:

Note: In the above formula, A1:D8 is the range that you want to use and A1 is the
cell with a particular font color that you want to sum.

4. Then press Enter key, and you will add up all cells with red font colors. If you
want to sum other font colored cells, please repeatedly enter the formula. You will
get the following result:
Count Or Sum Cells Based On Font Color With Kutools For Excel

May be the User Defined Function is troublesome for you to save and apply, here,
I will recommend you a handy too- Kutools for Excel, with its Count by
Color utility, you can quickly get the calculation result such as count, sum, average
cells and so on by the background color, font color, conditional formatting.

Kutools for Excel : with more than 120 handy Excel add-ins, free to try with no
limitation in 60 days.

Go to Download
Free Trial 60 daysPurchase
PayPal / MyCommerce

After installing Kutools for Excel, please do as follows:

1. Select the data range that you want to count and sum based on different colors.

2. Click Enterprise > Count by Color, see screenshot:


3. In the Count by Color dialog box, choose Standard formatting from the Color
method drop down, and select Font under the Count type drop down, see
screenshot:

4. And the cells with same font colors have been counted, added up, averaged and
so on. And then click Generate report button, you will get statistics in a new
workbook. See screenshot:
Download and free trial Kutools for Excel Now !

Count Or Sum Cells Based On Background Color With Kutools For


Excel

If you want to count or sum the cells with specific background color, Kutools for
Excel’s Count by Color feature also can help you, please do as follows:

1. Select the data range that you want to count or sum the cells based on
background color, and then enable this feature by clicking Enterprise > Count by
Color.

2. In the Count by Color dialog box, choose Standard formatting from the Color
method drop down, and select Background under the Count type drop down,
see screenshot:
3. Then click Generate report button, a report is generated based on the
background colors, see screenshot:

Click to know more about this Count by Color feature.


Download and free trial Kutools for Excel Now !

Count Or Sum Cells Based On Font / Background / Conditional


Formatting Color:

Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no
limitation in 60 days. Download and free trial Now!

Recommended Productivity Tools

Office Tab

Bring handy tabs to Excel and other Office software, just like Chrome,
Firefox and new Internet Explorer.

Kutools For Excel

Amazing! Increase your productivity in 5 minutes. Don't need any special


skills, save two hours every day!
200 New Features for Excel, Make Excel Much Easy and Powerful:
 Merge Cell/Rows/Columns without Losing Data.
 Combine and Consolidate Multiple Sheets and Workbooks.
 Compare Ranges, Copy Multiple Ranges, Convert Text to Date, Unit and Currency
Conversion.
 Count by Colors, Paging Subtotals, Advanced Sort and Super Filter,
 More Select/Insert/Delete/Text/Format/Link/Comment/Workbooks/Worksheets
Tools...

You might also like