0
votes

So basically I know nothing about creating scripts and I am trying to organize data on my google spreadsheet, What I want to do is to take a column for this example "column A" and have cell A1 be a dropdown list using range(sheet2!,A1:H1). On sheet 2 would be all the information matching each column eg.. sheet2:A1=Cars,A2:$A=Names of cars, sheet2:B1=Planes,B2:$B=names of planes.

Ok so back to sheet 1 I want to be able to select one of the options from the dropdown list eg. Cars and for the information already stored on sheet 2 to populate A2:A$ since A1 already has the dropdown list in it.

1
Can I get some up vote's or something? Bump. - Rey De Castro

1 Answers

1
votes

You posted this quite a while ago, but never got any comments or answers - assuming you haven't figured it out, I've posted some sample code below for you. You should take a look through the Google Apps Script Documentation though to get some more help.

function myFunction(e) 
{
   var entry = e.value; //Did the user enter Cars, Trucks, Planes, etc
   var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1"); //The sheet where we will put the data validation

  switch(entry)
  {

    case("Cars"): //If they put in cars
      var dv = SpreadsheetApp.newDataValidation();
      var options = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2").getRange("A2:A20").getValues(); //Grab the options for cars
      dv.setAllowInvalid(false); //Don't allow incorrect values
      //dv.setHelpText("Some help text here");
      dv.requireValueInList(options, true); //Require the options
      sheet.getRange("A2").setDataValidation(dv.build()); //Make the dropdown list on A1 for "Some Sheet Here" the list of car names
      break; //We're done
  }
}