Written by Allen Wyatt (last updated May 18, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021
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:
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) = cell.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.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12604) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
Sorting is one of the basic operations done in a worksheet. If your sorting won't work and you instead get an error ...
Discover MoreIf you have a mixture of numbers and text in a column and you want to sort based upon that column, the results may not be ...
Discover MoreUsing the sorting tools, on the toolbar, may result in some unwanted results, such as jumbled data. If this happens to ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments