Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

293
Views
How to loop through each column in a given row and then have the loop go automatically to the next column

I need to extract a data from this other sheet where the header will repeat itself by the number of items under it. So far I can only do this with the first column from the data source and I can’t seem to get the right code where the loop will go through the next column once it detects the first empty cell of the previous column.

Here’s where I am getting stuck

function filter(){

var sheet = SpreadsheetApp.getActiveSpreadsheet()
var data = sheet.getSheetByName("data")
var filter = sheet.getSheetByName("filter")

var dataRange = data.getDataRange().getValues();
var dataLr = data.getLastRow();
var dataLc = data.getLastColumn();

var row = 1
var col = 1

 for(var i=1; i < dataRange.length; i++){
  let targetAppName = filter.getRange(i+1,1)
  let targetQname = filter.getRange(i+1,2)

        targetQname.setValue(dataRange[i])
        targetAppName.setValue(dataRange[0][0])

}
}

I’m trying to get these results in another sheet tab:

|Names | Subjects | |:—————|:———————-:|

|Michael Lowry| Trigonometry|

|Michael Lowry| Biology|

And so on, until it reads all columns and rows of the data range

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Loop throught each column of each row

function loopthroughteachcolumnofarow() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getActiveSheet();
  const vs = sh.getDataRange().getValues();
  vs.forEach((r,i) => {
    r.forEach((c,j) => {
      //c is the value for vs[i][j];
    })
  })
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!