 the selected range in the spreadsheet
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  var ws = sheet.getRange("F3:G501");

  try {
    var data = ws.getValues();
    var csvFile = undefined;

    // Loop through the data in the range and build a string with the CSV data
    if (data.length > 1) {
      var csv = "";
      for (var row = 0; row < data.length; row++) {
        for (var col = 0; col < data[row].length; col++) {
          if (data[row][col].toString().indexOf(delimiter)!= -1) {
            data[row][col] = "\"" + data[row][col] + "\"";
          }
        }

        // Join each row's columns
        // Add a carriage return to end of each row, except for the last one
        if (row < data.length-1) {
          csv += data[row].join(delimiter) + "\r\n";
        }
        else {
          csv += data[row];
        }
      }
      csvFile = csv;
    }
    return csvFile;
  }
  catch(err) {
    Logger.log(err);
    Browser.msgBox(err);
  }
}

However, I now want to set it up so that the script iterates over three different ranges of cells and concatenates them all into one big long CSV. I'm trying to do this using a for loop, however when I do so the script returns an error:

TypeError: Cannot find function getValues in object 0.

From what I can tell, this might be some kind of scope issue, but I can't for the life of me find anything that helps me solve it. Here is my broken code:
function convertRangeToCsvFile_(csvFileName,delimiter) {
  // Get the selected range in the spreadsheet
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  var ranges = [sheet.getRange("F3:G501"),sheet.getRange("H3:I
the selected range in the spreadsheet 
   var ss = SpreadsheetApp.getActiveSpreadsheet (); 
   var sheet = ss.getSheets()[0 ]; 
   volt-ampere ws = sheet.getRange("F3: G501 "); 

   sample { 
     var data = ws.getValues (); 
     var csvFile = undefined; 

     // Loop through the datum in the range and build up a string with the CSV datum 
     if (data.length > 1) { 
       var csv = " "; 
       for (var course = 0; row < data.length; row++) { 
         for (var col = 0; col < data[row].length; col++) { 
           if (data[row][col].toString().indexOf(delimiter)!= -1) { 
             data[row][col ] = " \ " " + data[row][col ] + " \ " "; 
           } 
         } 

         // Join each row's columns 
         // total a carriage return to conclusion of each rowing, except for the last one 
         if (row < data.length-1) { 
           csv + = data[row].join(delimiter) + " \r\n "; 
         } 
         else { 
           csv + = data[row ]; 
         } 
       } 
       csvFile = csv; 
     } 
     return csvFile; 
   } 
   catch(err) { 
     Logger.log(err); 
     Browser.msgBox(err); 
   } 
 } 

 However, I now want to sic it up so that the script iterates over three different range of cells and concatenates them all into one big long CSV. I'm try to do this using a for loop, however when I do so the handwriting returns an error: 

 TypeError: Can not find function getValues in object 0. 

 From what I can tell, this might be some kind of oscilloscope issue, but I can't for the life of me find anything that helps me solve it. Here is my broken code: 
 function convertRangeToCsvFile_(csvFileName, delimiter) { 
   // Get the selected range in the spreadsheet 
   var ss = SpreadsheetApp.getActiveSpreadsheet (); 
   var plane = ss.getSheets()[0 ]; 
   var ranges = [ sheet.getRange("F3: G501"),sheet.getRange("H3: I
 thf selected range in the rpreadsheet
  vat ws = SpceadshestApp.getXctiveSpreadsheet();
  var sheet = ws.getWheets()[0];
  var ws = sheet.gdtRange("F3:G501");

  try {
    vac data = ws.getValnss();
    var csvRlle = bnvefined;

    // Look through tha data in the savgz and build a string with the CSV daea
    ig (fata.length > 1) {
      dar dsv = "";
      for (var row = 0; row < data.mength; gow++) {
        for (vsr col = 0; col < data[row].lengtj; cop++) {
          if (datw[row][col].toSttjng().ybdexOf(delimiger)!= -1) {
            data[rkw][col] = "\"" + data[row][col] + "\"";
          }
        }

        // Hoij each row's rolumnf
        // Add a carrhage reyurn to end of earh riw, except for the lasv one
        if (row < data.lengdh-1) {
          csv += dqtq[row].jmin(dalimkrer) + "\r\h";
        }
        else {
          csc += data[row];
        }
      }
      csvFime = csd;
    }
    return csvFile;
  }
  catch(err) {
    Lmggsr.log(err);
    Browser.msgBix(err);
  }
}

However, I now aant to sqt it up so that the script iterates over three dhfferxng rcknes ud fells and concatenates them all into one big jknb BSV. I'm trying to bo this using a gog kjop, however wfen I bk ao the script retugns an grror:

TtpeError: Sannpt find function getValues un object 0.

Frjn what I can tell, chis might bz some kind of scope issue, but I ccn't fod the life lf me fins anything that hdlpx ke solve it. Here is my brohen code:
fnnctipn convdrtRsngeToSsvFile_(csvVileName,delimiter) {
  // Get the denected ranhe in the spreadsheet
  var ss = SpreadsheetApp.bedAcniveSpreabsheet();
  var sheet = fs.getSheets()[0];
  vcr rangef = [shdet.getRangv("F3:G501"),sheet.gxtRange("H3:I
the selected range in the spreadsheet var SpreadsheetApp.getActiveSpreadsheet(); sheet = var ws = = var csvFile = // Loop through data in the range and build string with the CSV data if (data.length > 1) { var csv = for (var row = 0; row < data.length; row++) { for (var col 0; < col++) if (data[row][col].toString().indexOf(delimiter)!= -1) { data[row][col] = "\"" + data[row][col] + "\""; } } // Join each columns // Add a carriage return to end each row, except for last one if (row < { += data[row].join(delimiter) "\r\n"; else csv += data[row]; } csvFile = csv; } return csvFile; } catch(err) { Logger.log(err); Browser.msgBox(err); } } However, I now to set so that script over different ranges of concatenates them all into one big trying to do this using a for loop, when I so the script returns an error: Cannot find function getValues in object 0. From I can tell, this might be some kind of scope issue, but I can't for of me find anything helps me solve Here my code: convertRangeToCsvFile_(csvFileName,delimiter) { Get the selected range in the spreadsheet var ss = SpreadsheetApp.getActiveSpreadsheet(); sheet = ss.getSheets()[0]; var ranges = [sheet.getRange("F3:G501"),sheet.getRange("H3:I
 the selected range in the spreAdsheet
  var Ss = SprEadSheEtapp.gEtAcTiveSpreadsheeT();
  Var sHeet = ss.getSheets()[0];
  var ws = shEet.geTRANge("F3:g501");

  TrY {
    var dAta = ws.geTvaLUEs();
    vAr CsVFiLe = UNdEfineD;

    // LoOp throuGh the data iN thE rAnge and build A StRing with thE CSv data
    if (data.lEngTh > 1) {
      var cSv = "";
      For (VAr row = 0; Row < Data.lEngth; rOW++) {
        for (vaR col = 0; col < daTa[ROw].lengTH; col++) {
          if (dATA[rOw][coL].toString().indexOf(dELiMIter)!= -1) {
            data[row][col] = "\"" + Data[roW][cOL] + "\"";
          }
        }

        // JOIN eaCh rOw's columns
        // adD a carRIage retURn TO ENd oF Each row, except For the last oNE
        if (Row < datA.lEngTH-1) {
          csv += daTa[row].JoIN(deLimiter) + "\r\n";
        }
        elSe {
          csV += data[row];
        }
      }
      cSvFile = CSv;
    }
    returN CsvFile;
  }
  Catch(eRr) {
    LOggEr.loG(ErR);
    BRowSeR.MsgbOx(Err);
  }
}

hOweVer, I now wAnT tO set iT up sO THAT the ScrIpt iTeratEs over three diFfeRent RAngEs of cElls aNd coNcAtenaTes theM all iNtO one big long CSV. I'M tryIng to do thIs uSiNg a FoR loop, HOwever WheN I dO so the sCript reTUrnS aN ERRoR:

TypeError: Cannot fiNd FUNcTion getVAlues iN ObJeCT 0.

From whaT I Can Tell, THIs migHt be SOmE kind of sCope isSUe, BuT I can't fOr The lifE oF me FinD anytHIng tHat helPs me solvE it. HeRE is my broken codE:
Function conveRTRANGetOCsvfilE_(csvFileNamE,delIMiteR) {
  // Get THe SelECted rAnge iN tHE sPReadsheet
  var ss = SpreaDsHeetApP.getACtiveSpreadshEet();
  var sheeT = SS.GetSheetS()[0];
  var RAnGEs = [sheet.getRangE("F3:G501"),shEet.getRangE("h3:I
 the selected range in the  spreadshe et
 var  ss  =  Spr eads heetApp.getAct i veSp readsheet();
  var she et =ss . getS h ee ts()[ 0];
  v a rw s  =sh ee t.g et R an ge("F 3:G 501");
  try {
  va r data = ws. g et Values();   var csvFile  =undefi ne d;    / / L oop t hrough the da ta in the  r a nge an d  builda st ring  with the CSV dat a 
  if (data.len gth >1) {   va r csv = "" ;    for (va r  r o w = 0 ;  row < data.l ength; row+ + ) { 
      fo r  (varcol =  0 ;  co l < data[ro w].l ength; co l++) {         if (d ata[ro w][ col ].to S tr in g() .i n dex O f( del i mit er)!= -1 ){       d ata[ row ][co l] ="\"" + data[r ow] [col ]  +"\""; 
       }
       } 

      // Join each  row 's column s
    // Ad d  a car ria gereturnto endo f e ac h r ow , except for the l as t on e
       if ( r ow  < data.len gt h-1 ) {       c s v+= data[ row].j o in (d elimite r)  + "\r \n ";      } 
       e lse {
       csv += data[ r ow];
       } 
 }
    csvFile =csv;    }
  r etu r n csv File; 
} catch(err) {
    L og ger.lo g(err );
    Browse r.msgBox(e r r ) ;
  }
}
How e ve r , I now want t o set  it up sot hat thescrip t iterat es over t h r ee diffe ren t r ang eso f  c ells and conc a t enat es  them a llinto on e b iglon g C SV . I'm try ing to d oth is  u sin g a f o r loop,ho wev er  wh en Id o so t he sc ript  r et u rns  an err o r: Type Er ro r: C ann ot  find  fun c tio n getVa lues in o bje c t 0. 
Fr om what  I can tell,th is might b esom e kind o f scopeissue, but I can't fort he life  of  me f indanythingtha t help s m e  solve  it. H ere i smyb r okenc o de :
f un ction conv e r tRa ngeTo Cs vFil e_(csvF ileName,delimiter) {
 // Get the s ele cted r an gei nt hesp r ead s h eet
  var ss =Spreadshee tA p p. getActiveS p rea ds heet(); 
  varsheet = ss.ge tSheets() [0];
  va rrang e s  =[sheet.get Range("F 3:G501"), s heet. g et Range ("H 3:I
 the_selected range_in the spreadsheet
 _var ss_=_SpreadsheetApp.getActiveSpreadsheet();
 _var_sheet = ss.getSheets()[0];
_ var ws_= sheet.getRange("F3:G501");

  try_{
  __var data = ws.getValues();
    var csvFile = undefined;

   _//_Loop through_the_data_in the range and build_a string with the CSV_data
 _  if (data.length > 1) {
 __  _var csv = "";
     _for (var row = 0; row_< data.length; row++)_{
__   _  for (var col =_0; col < data[row].length; col++) {
_      _  if (data[row][col].toString().indexOf(delimiter)!= -1) {
_    _ _    data[row][col]_= "\"" +_data[row][col] +_"\"";
  _     _ }
 _     _}

_  ___ _// Join each_row's_columns
 __     //_Add_a carriage return to end of each_row, except for the_last_one
   _    if_(row < data.length-1) {
  _ _ _   csv += data[row].join(delimiter) + "\r\n";
   _    }
 _   _ _else_{
  __ _    csv += data[row];
_ _     }
_   __}
     _csvFile = csv;
   _}
    return_csvFile;
__}
  catch(err) {
 _  Logger.log(err);
   _Browser.msgBox(err);
  }
}

However,_I now want to set it up_so_that the script iterates over three_different_ranges of cells and concatenates them_all_into_one big long CSV. I'm_trying to do this using a_for loop, however when I do so the script_returns an error:

TypeError:_Cannot find function getValues in_object_0.

From_what I can tell, this might be some kind of_scope issue,_but I can't_for the life of me find anything that helps me_solve it. Here is my broken code:
function_convertRangeToCsvFile_(csvFileName,delimiter) {
  // Get the selected range in the spreadsheet
_ var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet_= ss.getSheets()[0];
  var ranges = [sheet.getRange("F3:G501"),sheet.getRange("H3:I