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

248
Views
Why am I getting TypeError: Cannot read property '0' of undefined error in google apps script?

I am just trying to bold the first column data in the sheet.

function formatColumnHeader(){
var thisSheet = SpreadsheetApp.getActiveSheet();
var dataRange = thisSheet.getDataRange();
var dataValues = dataRange.getValues();

for(var row =1;row<dataValues.length;row++){
 dataRange[row][0].setFontWeight('bold');
}
}

But I get TypeError: Cannot read property '0' of undefined error. What am I doing wrong here?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can try range.offset:

function formatColumnHeader(){
  const thisSheet = SpreadsheetApp.getActiveSheet(),
    dataRange = thisSheet.getDataRange();
  dataRange.offset(0, 0, dataRange.getNumRows(), 1).setFontWeight('bold');
}

Or if you have no need for dataRange, try getRange() to get only the range that you need:

function formatColumnHeader(){
  const thisSheet = SpreadsheetApp.getActiveSheet();
  dataRange = thisSheet.getRange(1, 1, thisSheet.getLastRow()).setFontWeight('bold');
}
about 4 years ago · Juan Pablo Isaza 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!