Note: The other languages of the website are Google-translated. Back to English

How to filter rows based on cell color in Google sheet?

Normally, we can filter rows by a certain color in Excel quickly with the Filter feature, but, in Google sheet, the Filter function does not support this operation. This article, I will talk about how to filter rows by color in Google sheet.

Filter rows based on color in Google sheet


Filter rows based on color in Google sheet

Please apply the following steps to filter data based on color.

1. Click Tools > Script editor, see screenshot:

2. In the opened project window, please copy and paste the below script code to replace the original code in the code module, see screenshot:

function getHex(input) {
  return SpreadsheetApp.getActiveSpreadsheet().getRange(input).getBackgrounds();
}

3. And then save the code window, and a prompt box is popped out to remind you to give the project a name, see screenshot:

4. After saving the script code, go back the sheet, and enter this formula: =getHex("A2:A16") into a blank cell next to your data range, and then press Enter key, the color index of each row has been displayed in the helper column, see screenshot:

5. Then you just need to filter rows based on this helper column, please click the helper column header, and then click Data > Filter, see screenshot:

6. And then click the drop-down button in the helper column, in the expanded pane, choose and check the color index that you want to filter from the list box, see screenshot:

7. Click the OK button, the rows which filled with the specific cell color have been filtered as following screenshot shown:


The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office / Excel 2007-2021 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Comments (17)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Top, Danke!
This comment was minimized by the moderator on the site
Just a note if this isn't working for you, the quotation marks used in the example above don't parse a formula correctly and give you a "Formula Parse Error".

The correct one is:

=getHex("A2:A16")

rather than:

=getHex(“A2:A16”)
This comment was minimized by the moderator on the site
Hi, Polynon,
Thank you for your comment, the double quote around the cell reference should be English punctuation.
I have updated it.
This comment was minimized by the moderator on the site
i want use it, but dont working :-/
This comment was minimized by the moderator on the site
This is a great script it really helped me solve a problem, however I modified it a bit because my range is not fixed, I keep adding rows to the sheet and I don't want to modify the formula everytime I add a new row, so I used the following formula instead:

=ARRAYFORMULA(IF(NOT(ISBLANK(A2:A)),getHex("A2:A"),""))

The problem is when I change the color of a column the hex value does not change even if I refresh the sheet, the only solution I found is to delete the formula then paste it again so it loads again, anyone could help with a solution to this?
This comment was minimized by the moderator on the site
This is a great script it really helped me solve a problem, however I modified it a bit because my range is not fixed, I keep adding rows to the sheet and I don't want to modify the formula everytime I add a new row, so I used the following formula instead:

=ARRAYFORMULA(IF(NOT(ISBLANK(A2:A)),getHex("A2:A"),""))

The problem is when I change the color of a column the hex value does not change even if I refresh the sheet, the only solution I found is to delete the formula then paste it again so it loads again, anyone could help with a solution to this?
This comment was minimized by the moderator on the site
I understand that the topic is about a script for such a need. But a simpler option can be to handle conventions by color. Example: Green color indicates CLIENT, Color Orange. INTERESTED, Color Yellow indicates NOT INTERESTED .. Then add a column status and then filter for the desired state.
This comment was minimized by the moderator on the site
Great workaround! I tried repeatedly to highlight duplicates in an Excel spreadsheet then sort by cell color but since the file was so large (373K + rows) the sort would "hang", and never complete. I decided to try Google Sheets and although I could only format about 100K rows at a time (had to do a format 4x) your workaround worked perfectly. Plus, scrolling down the page with Google Sheets was infinitely faster than with Excel. Thanks for the great hack!
This comment was minimized by the moderator on the site
Awesome job, it works exactly like the explanation.Thank you
This comment was minimized by the moderator on the site
there's a question that it kept showing "Range not found",how can i fix it
This comment was minimized by the moderator on the site
Thank you. Awesome
This comment was minimized by the moderator on the site
Superb! very useful! Thanks a million! Cheers!
This comment was minimized by the moderator on the site
Thanks a lot! It helped.
This comment was minimized by the moderator on the site
ty it works
This comment was minimized by the moderator on the site
It worked for me, but not for alle colors. I don't know why.
But anyway: Thank a lot!
This comment was minimized by the moderator on the site
What if only certain cells in a row were colored? How can I use this method to notate which ROWS contain a particular color?
This comment was minimized by the moderator on the site
See also how-to-pass-a-range-into-a-custom-function-in-google-spreadsheets
https://webapps.stackexchange.com/questions/10629/how-to-pass-a-range-into-a-custom-function-in-google-spreadsheets

This then gives for example

=getHex(CELL("address",A1))
=getHex(CELL("address",A1)&":"&CELL("address",A2))

etc
There are no comments posted here yet

Follow Us

Copyright © 2009 - www.extendoffice.com. | All rights reserved. Powered by ExtendOffice. | Sitemap
Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.
Protected by Sectigo SSL