Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8124197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:23:24+00:00 2026-06-06T06:23:24+00:00

I have a Google spreadsheet and I am having real difficulty trying to work

  • 0

I have a Google spreadsheet and I am having real difficulty trying to work out the code I require to select a number of rows.

The only rows I want to select are the rows that have a value or formula in one of the columns (lets say column B).

I cannot order the sheet by the column and only select the first x values.

I am thinking I need to loop through every row in the sheet and determine if column B is empty but I don’t know how to do this or how to check if the cell contains a value or a formula. If it contains a formula then this must be preserved in preference to the value.

How do I select only the rows from a Google Spreadsheet where values or formulas in a certain column are not empty using Google Apps Scripts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:23:26+00:00Added an answer on June 6, 2026 at 6:23 am

    This should do what you want… maybe it need some debugging because I didn’t test it since I’m not sure about what you really want 😉

    function copynotempty(){
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var sh = SpreadsheetApp.setActiveSheet(ss.getSheets()[0])
      var col = 1 ; // choose the column you want to check: 0 = col A, 1= col B ...
      var range = sh.getDataRange();
      var values=range.getValues();// data is a 2D array, index0 = col A
      var formulas=range.getFormulas();// data is a 2D array, index0 = col A
      var target=new Array();// this is a new array to collect data
       for(n=0;n<range.getHeight();++n){
         if (values[n][col]!=''|| formulas[n][col]!=''){ ; 
            for (cc=0;cc<range.getWidth();++cc){
                    if (formulas[n][cc]!=''){target[n][cc]=formulas[n][cc]}else{target[n][cc]=values[n][cc]}
        // if the cell has a formula copy it or else copy the value, do that for the whole row
    // (this also defines and apply the 'priority' you mentioned in your question, I wasn't sure if it should apply to the whole row or only on column B)
                    }
                  }
                }
                if(target.length>0){// if there is something to copy
              var sh2=SpreadsheetApp.setActiveSheet(ss.getSheets()[1]); //second sheet of your spreadsheet
              sh2.getRange(1,1,target.length,target[0].length).setValues();// paste the selected values in the 2cond sheet
              }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out how to use Google Api for accessing/editing Google SpreadSheet.
I have a google spreadsheet in which I want a date with only the
I have a Google Spreadsheet with many hidden rows in it, and I want
I have a bunch of rows in a Google Spreadsheet that look as such:
I have a Google Spreadsheet with 3 columns that are either blank or have
I have a google spreadsheet that uses this function: =SUM(E:E) - SUM(C:C) It adds
I would like to create a HLOOKUP in google doc spreadsheet: =HLOOKUP(aValue;DEC10!$D$2:$W$3;2;FALSE) I have
I have a spreadsheet (in Google Docs, but can be any spreadsheet) with a
I have the following formula that works out the value of all the rows
I'm new to Google Documents and have set up a spreadsheet that accesses the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.