Google-sheets – Google Sheets onEdit uppercase script

google sheetsgoogle-apps-script

I'm collecting one-letter responses from users in a Google Sheet and would like their responses to be made uppercase as they are input, but only within the cells D5-J[infinity]. I found a few responses on how to do this and Frankensteined the following code in Script Editor, but it's not firing. What's wrong?

function onEdit(e) {
  var column = e.range.getColumn();
  var row = e.range.getRow();

  if ( col >=  4 && col <= 10 ) {
    if ( row >= 5 ) {
      if (typeof e.value != 'object') {
        e.range.setValue(e.value.toUpperCase());
      }
    }
  }
}

Best Answer

I realized that the problem was just that I defined the variable for the columns as "column" but then used a different variable in the code: "col". Simple user error. :)

The correct formula is as follows:

function onEdit(e) {
  var column = e.range.getColumn();
  var row = e.range.getRow();

  if ( column >=  4 && col <= 10 ) {
    if ( row >= 5 ) {
      if (typeof e.value != 'object') {
        e.range.setValue(e.value.toUpperCase());
      }
    }
  }
}