Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to delete all rows containing specific text within a column in Google sheets?

Supposing, you have a range of data in a google sheet, now, you would like to delete the rows based on cell values in a column. For example, I want to delete all rows which contain the text “Complete” in Colum C. This article, I will talk about how to solve it in Google sheets.

Delete all rows containing specific text within a column with script code


Delete all rows containing specific text in Excel worksheet:

If you want to remove all rows which contain a specific value in a column, the Kutools for Excel's Select Specific Cells feature can help you to select all rows matched the criteria, and then you just need to delete the rows at once.

doc delete rows containing 5

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!


Delete all rows containing specific text within a column with script code


To remove all rows which include the specific text in a column, the following script code can do you a favor, please do as this:

1. Click Tools > Script editor, see screenshot:

doc delete rows containing 1

2. In the new opened code window, copy and paste the following code into the blank code window, see screenshot:

function deleteRows() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = ss.getSheetByName('delete containing');
  var r = s.getRange('C:C');
  var v = r.getValues();
  for(var i=v.length-1;i>=0;i--)
    if(v[0,i]=='Complete')
      s.deleteRow(i+1);
};

doc delete rows containing 2

Note: In the above code, “delete containing” is the sheet name containing the data you want to delete, “C:C” is the column with specific text you want to delete from, “Complete” is the specific text that you want to delete rows based on, please change them to your need.

3. Then save this code, and then click Run button in the code window to execute this script code, see screenshot:

doc delete rows containing 3

4. And all rows which containing the specific text “Complete” have been deleted at once, see screenshot:

doc delete rows containing 4


Recommended Productivity Tools for Excel

kte tab 201905

Kutools for Excel Helps You Always Finish Work Ahead of Time, and Stand Out From Crowd

  • More than 300 powerful advanced features, designed for 1500 work scenarios, increasing productivity by 70%, give you more time to take care of family and enjoy life.
  • No longer need memorizing formulas and VBA codes, give your brain a rest from now on.
  • Become an Excel expert in 3 minutes, Complicated and repeated operations can be done in seconds, 
  • Reduce thousands of keyboard & mouse operations every day, say goodbye to occupational diseases now.
  • 110,000 highly effective people and 300+ world-renowned companies' choice.
  • 60-day full features free trial. 60-day money back guarantees. 2 years of free upgrade and support.

Brings Tabbed Browsing and Editing to Microsoft Office, Far More Powerful Than The Browser's Tabs

  • Office Tab is designed for Word, Excel, PowerPoint and Other Office Applications: 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!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    DylJohBar · 10 days ago
    This seems to work only if a cell contains only the text specified. I want to delete rows with cells that contain other text including the text specific. I have a bunch of email addresses and want to be rid of rows containing Gmail addresses, therefore I'm looking for cells containing 'gmail.com'.

    No luck here.
    • To post as a guest, your comment is unpublished.
      Josh Jones · 10 days ago
      Replace this line: if(v[0,i]=='Complete')
      With this: if(v[0,i].indexOf('gmail') > -1)
  • To post as a guest, your comment is unpublished.
    Moh · 7 months ago
    Hello,
    Can modify the below code to delete the coloured row instead of text


    function deleteRows() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var s = ss.getSheetByName('delete containing');
    var r = s.getRange('C:C');
    var v = r.getValues();
    for(var i=v.length-1;i>=0;i--)
    if(v[0,i]=='Complete')
    s.deleteRow(i+1);
    };
  • To post as a guest, your comment is unpublished.
    ibrahem · 7 months ago
    Hello,
    Can I modify the below code to delete a coloured cell instead of specific text:


    function deleteRows() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var s = ss.getSheetByName('delete containing');
    var r = s.getRange('C:C');
    var v = r.getValues();
    for(var i=v.length-1;i>=0;i--)
    if(v[0,i]=='Complete')
    s.deleteRow(i+1);
    };
  • To post as a guest, your comment is unpublished.
    Martha · 10 months ago
    Does nothing at all, not sure how to fix this.