Separating Cells Based on Text Color

by Allen Wyatt
(last updated May 30, 2017)

5

Thomas has a column that contains nothing but text values, such as sentences and phrases. Some cells show their text in red and the rest are in black. He would like a way to separate the text such that black-text cells remain in the column and red-text cells are moved to the next column.

There are a couple of ways you can approach this issue. Perhaps the easiest approach is to simply sort or filter the column that has the text values in it. Excel allows you to filter and sort based on text color, which means that either you could see just the red-text cells or put all the red-text cells into a contiguous range. Then it is an easy task to cut the red-text cells and paste them into the next column.

For instance, here's how you would do the sort:

  1. Select the cells that contain your text values.
  2. Display the Data tab of the ribbon.
  3. Click the Sort tool in the Sort & Filter group. Excel displays the Sort dialog box.
  4. Using the Sort On drop-down list, choose Font Color.
  5. Use the Order drop-down list to indicate which color you want to be shown first in the sorted list. (This is where you would pick your red color. The drop-down list includes each color detected in the range you selected in step 1.)
  6. Click on OK.

Now your cells are sorted, by color, with the color specified in step 5 at the beginning of the cell range. You can easily copy it or move it to a different column. You could use the same general steps if you wanted to filter your text values based on font color.

If you prefer, you could also use a macro to move your red-text cells. Here's an example that copies the cell value and font color one cell to the right.

Sub MoveRedText1()
    Dim c As Range

    If Selection.Columns.Count > 1 Then Exit Sub

    For Each c In Selection
        If c.Font.Color = vbRed Then
            c.Offset(0, 1) = c.Value
            c.Offset(0, 1).Font.Color = vbRed
            c.ClearContents
            c.Font.Color = vbBlack
        End If
    Next c
End Sub

To use the macro, just select the cells you want to analyze and then run the macro. It doesn't copy all formatting of the cells it is moving; if that is critical you can actually use a much simpler macro to do the moving.

Sub MoveRedText2()
    Dim c As Range

    For Each c In Selection
        If c.Font.Color = vbRed Then _
          c.Cut Destination:=c.Offset(0, 1)
    Next c
End Sub

If you use either of these macros and your red-text cells don't move, it could be because the cells don't actually use red text. There are many different shades of red that can be displayed in Excel, so you'll need to tweak the macros to make sure that you are checking for the proper font color.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12604) applies to Microsoft Excel 2007, 2010, and 2013.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Avoiding the Update Links Message

Word allows you to establish links from one document to another. When you open a document containing these links, you may be ...

Discover More

Compound Page Numbering

Simple page numbering is easy to add to your documents. More complex numbering (such as two numbering schemes in the same ...

Discover More

Selective Undo

Ever wonder why you can't undo just a single edit you made a few minutes earlier? The short answer is that it could make your ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Sorting Dates by Month

Sorting by dates is easy, and you end up with a list that is in chronological order. However, things become a bit more tricky ...

Discover More

Performing Complex Sorts

One way you can easily work with data in a worksheet is to sort it into whatever order you find most helpful. Excel allows ...

Discover More

Sorting for a Walking Tour

Want to sort addresses by even and odd numbers? By using a formula and doing a little sorting, Excel can return the addresses ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two more than 4?

2017-10-18 04:35:50

Peter Atherton

Hossam

Two versions. The first has less to do, use for the first time. The second assumes there is data already in column A so use this to update a list.

Sub CopyRedVals()
Dim c As Range, addr As String
Dim wks As Worksheet
Dim r As Long

Set wks = Sheets("Data")
r = 2

For Each c In Selection
addr = c.Address
If Range(addr).Font.Color = RGB(255, 0, 0) Then
c.Copy wks.Cells(r, 1)
r = r + 1
End If
Next c
End Sub

Sub CopyRedVals2()
Dim c As Range, addr As String
Dim wks As Worksheet
Dim r

Set wks = Sheets("Data")

For Each c In Selection
addr = c.Address
If Range(addr).Font.Color = RGB(255, 0, 0) Then
With wks
r = .Range("A1").End(xlDown).Offset(1, 0).Row
c.Copy wks.Range("A" & r)
End With
End If
Next c
End Sub

HTH
Peter


2017-10-17 18:33:56

Peter Atherton

Philip

Not as far as I know. I tried this with Visual Basic, and it is easy to ascribe a colour to a cell character. However, I don't know how you would read the format of each character.


2017-10-14 14:09:50

Hossam Mohamed

I want a macro that copy cells with red font (code 255) from column E in Sheet "Template" to the first empty row in column A in sheet "Data".

I would be grateful for your help


2017-05-30 11:13:07

Philip

Is there a way to pick up whether PART OF the text in a cell is in a certain color ?


2013-04-27 08:44:09

Dennis

Good stuff.
Thx.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.