How To Extract Text Based On Font Color From A Cell in Excel
How To Extract Text Based On Font Color From A Cell in Excel
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.
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
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.
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.
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
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!
Amazing! Using Tabs In Excel Like Firefox, Chrome, Internet Explore 10!
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.
1
Public Function CountColour(pRange1 As Range, pRange2 As Range) As Double
2
'Update 20140210
3 Application.Volatile
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:
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.
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
1. Select the data range that you want to count and sum based on different colors.
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 !
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:
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!
Office Tab
Bring handy tabs to Excel and other Office software, just like Chrome,
Firefox and new Internet Explorer.