Sheets Mega Tools
Sort by Color in Google Sheets™
Reorder rows in your Google Sheets™ selection by cell background or text color. Keep related highlights together automatically with Text To Table Converter.
Sort by Color helps you organize data when you've highlighted rows with different colors. Group similarly colored rows together and optionally define a custom priority order for your color scheme.
How to use Sort by Color
- Select your range
Highlight the rows you want to sort. This tool works on the current selection only (helper text is shown in the panel).
Caution: The selection cannot contain merged cells. If your selection has merged cells, you'll be asked to unmerge them first.
- Open the tool
Open the add-on sidebar, expand Sheets Mega Tools, go to Rows & Columns, and click Sort by Color.
You can also use the Sheets Mega Tools menu shortcut to open the same sidebar section.
- Configure sort options
Click the caret button to expand the options panel:
Color Basis:
- Background (default) - Sort by cell background color
- Text - Sort by cell text color
Sort Order:
- Auto (default) - Colors appear in the order they first appear in your data
- Custom priority - Define specific color order using color pickers (unlisted colors appear after your custom list)
Additional Options:
- Blanks last - Move cells with no color to the bottom (default: off)
- Secondary sort - For rows with the same color, sort alphabetically A→Z by the first character of text content (ties only)
- Run the sort
Click Sort selection to reorder rows based on your configured options.
- Review status message
After sorting, a status message confirms:
- Color basis used (Background or Text)
- Sort order applied (Auto or Custom)
- Number of rows sorted
How It Works
Row Reordering
- Rows are reordered based on the color in the first column of your selection
- The entire row moves together, preserving all data
- Selection shape is preserved (same dimensions before and after)
Color Sorting Logic
Auto Order (Default):
- Colors are sorted in the order they first appear in your data
- Example: If Red appears first, then Blue, then Green, that's the sort order
Custom Priority:
- Define specific colors using color pickers (e.g., Red → Yellow → Green)
- Colors matching your list are sorted in your specified order
- Colors not in your list appear after your prioritized colors
- Blank (no color) cells can be forced to the bottom with "Blanks last" toggle
Secondary Sort
When multiple rows have the same color:
- Rows are sorted alphabetically A→Z by the first character of their text content
- Sorting is case-insensitive
- This only applies when there are "ties" (multiple rows with identical colors)
Data Preservation
The sort operation preserves:
- ✅ Cell values (numbers, text, dates)
- ✅ Cell formulas (functions remain intact)
- ✅ Cell notes/comments
- ✅ Background colors
- ✅ Font colors
- ✅ Cell formatting
Use Cases
- Priority tracking - Group tasks by color-coded priority (Red = Urgent, Yellow = Medium, Green = Low)
- Status visualization - Organize items by status colors (Red = Blocked, Yellow = In Progress, Green = Complete)
- Category grouping - Sort data by color-coded categories after manual highlighting
- Quality control - Group items by review status colors
- Project management - Organize tasks by color-coded project phase or team
- Data analysis - Group rows by color highlights from conditional formatting or manual review
Examples
Example 1: Auto Order (Default)
Your data has rows highlighted:
- Row 5: Red
- Row 3: Blue
- Row 7: Red
- Row 2: Green
- Row 8: Blue
After sorting with Auto order:
- Rows with Red (first color seen)
- Rows with Blue (second color seen)
- Rows with Green (third color seen)
Example 2: Custom Priority
You define priority: Green → Yellow → Red
Your data has rows: Red, Blue, Yellow, Green, Purple
After sorting:
- Green rows (1st in your custom priority)
- Yellow rows (2nd in your custom priority)
- Red rows (3rd in your custom priority)
- Blue and Purple rows (not in custom list, appear after)
Example 3: With Secondary Sort
Multiple rows have Red background:
- "Zebra" (Red)
- "Apple" (Red)
- "Mango" (Red)
After sorting with secondary sort enabled:
- "Apple" (Red, sorted A→Z)
- "Mango" (Red, sorted A→Z)
- "Zebra" (Red, sorted A→Z)
Important Notes
Scope Limitation
Sorting is limited to the selected range to keep the operation predictable and safe. If you need to sort an entire sheet, use Google Sheets™ built-in Data → Sort range feature.
Merged Cells
The tool rejects selections containing merged cells. If you have merged cells in your selection:
- Unmerge the cells first (Format → Merge cells → Unmerge)
- Run the sort
- Re-merge if needed afterward
Undo Support
The sort operation uses the Sheets API, which means:
- ✅ You can undo the sort with Ctrl+Z (Cmd+Z on Mac)
- ✅ The operation appears in your sheet's edit history
- ✅ All original data is preserved if you need to revert
Performance
For very large selections (10,000+ rows), the sort may take a few moments. The tool will show a loading indicator while processing.
Tip: When working with color-coded data, consider using Sort by Color in combination with Find Duplicate Rows or Cell Value Heatmap for comprehensive data organization.
Note: This tool is part of Sheets Mega Tools, available only in Google Sheets™. It complements the built-in sort features by adding color-based organization capabilities.