title: Google sheets - Script to use columns headings?
body: <p>Have two questions here, I have a rather complex spreadsheet where I need to move around columns and it will take forever to update the queries as it's going to be a regular task. I've decided to update the query to use a column header which hopefully will make it more flexible. </p>
  
  <p>I thought I was on the right track with the script below but it doesn't do anything in the sheet</p>
  
  <pre><code>  function getHeader(sheet, headings) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  
  var headings = sheet.getDataRange().offset(0, 0, 1).getValues()[0];
  
  
  }
  </code></pre>
  
  <p>This is how I'm calling the script in the sheet </p>
  
  <pre><code>=query(A:F,"select "&amp;getHeader("Name")&amp;" where "&amp;getHeader("Role")&amp;" contains 'Cook' ",0)
  </code></pre>
  
  <p>I've got it working using a query below which seems to work well, I'm interested to know what would be better Script or query? </p>
  
  <pre><code>=query(A:E,"select "&amp;char(64+match("Name",1:1,0))&amp;" where "&amp;char(64+match("Role",1:1,0))&amp;" = 'Cook' ")
  </code></pre>