title: Add dummy parameter to Custom function for Google sheets
body: <p>I have the custom function below; it moves columns from one sheet to a different sheet in Google Sheets</p>
  
  <p>I got it here
  <a href="https://stackoverflow.com/questions/17305700/non-contiguous-column-copy-from-one-spreadsheet-to-another-in-google-apps">Non-contiguous column copy from one spreadsheet to another in google apps</a></p>
  
  <p>I need to add a <code>dummy</code> parameter to it so I can get it to refresh the data it pulls</p>
  
  <p>I tried simply doing this: <code>function copyColumns(sourceRange,start,sheetKey, dummy)</code> (which has worked for other custom functions) </p>
  
  <p>but I keep getting an error:</p>
  
  <pre><code>Problem getting sheet1 - Exception: You do not have permission to perform that action. (line 31).
  </code></pre>
  
  <p>Which is: <code>throw "Problem getting sheet" + sheetKey + " - " + err;</code></p>
  
  <p>I know some <code>VBA</code> but am new to Google script writing, I have tried but have not worked out how to do this</p>
  
  <p>Thanks</p>
  
  <pre><code>/* =copyColumns("MyDataSheet!C,A,W",8) */
  
  function copyColumns(sourceRange,start,sheetKey) {
    // Initialize optional parameter
    if(!sheetKey &amp;&amp; typeof start!== "number") {
      sheetKey = start;
      start = 1;
    } else {
      start = start || 1;
    }
    // Check SourceRange Input
    var inputRe = /^((.*?!)(?=[a-z],?|[a-i][a-z]))?[a-i]?[a-z](,[a-i]?[a-z])*$/i;
    if(!inputRe.test(sourceRange))
      throw "Invalid SourceRange: " + sourceRange;
  
    // Check Start Row
    if(typeof start !== "number")
      throw "Starting row must be a number! Got: " + start;
    if(start % 1 !== 0)
      throw "Starting row must be an integer! Got: " + start;
    if(start &lt; 1)
      throw "Starting row can't be less than 1! Got: " + start;
  
    // Get the Source Sheet
    try {
      var ss = sheetKey
             ? SpreadsheetApp.openById(sheetKey)
             : SpreadsheetApp.getActiveSpreadsheet();
    }  catch(err) {
      throw "Problem getting sheet" + sheetKey + " - " + err;
    } 
    var sheetName = sourceRange.match(/^.*?(?=!)/);
    var sheet = sheetName
              ? ss.getSheetByName(sheetName[0])
              : ss.getActiveSheet();
  
    // Check that everything is still valid
    if(!sheet)
      throw "Could not find sheet with name: " + sheetName;
    if(start &gt; sheet.getLastRow())
      throw "No data beyond row: " + start + " Last row: " + sheet.getLastRow();
  
    // Get the values
    var lastCol = sheet.getLastColumn();
    var lastRow = sheet.getLastRow()-start+1;
    var values = sheet.getRange(start,1,lastRow,lastCol).getValues();
  
    // Get the desired columns from the string
    var desiredColMatch = sourceRange.match(/([a-i]?[a-z](,[a-i]?[a-z])*)$/i);
    var desiredColumns = desiredColMatch[0].toUpperCase().split(",");
  
    // In case the column we are trying to grab doesn't exist in the sheet
    var lastColId = sheet.getMaxColumns() - 1; // Array is 0 indexed, Sheet is 1
  
    // Get the numerical values of the passed in Column Ids
      var columns = desiredColumns.map(function(colId){
      var num = colId.length - 1; // 0 or 1
      var colNum = colId.charCodeAt(num)-65+num*26*(colId.charCodeAt(0)-64);
      if(colNum &gt; lastColId)
        throw "Invalid Column: " + colId + " - Column not in: " + sheetName;
      return colNum;
    });
  
    //Map the values to a new array of just the columns we want
    return values.map(function(row){
      return columns.map(function(col){
        return row[col]
      })
    });
  }
  </code></pre>