0

I am recreating and expanding on a doc I had previously made. I have already brought in the script I had used originally, and tweaked it where I believed appropriate to get it working in this sheet, but I must have missed something. Editable samples of the 3 spreadsheet files involved can be found here. These files are a sample "Price List", "Catalog"(which aggregates manufacturer names from all price lists, and also has a "Catalog" tab for misc items not sold by one of my primary vendors), and "Addendum B" which is the file I require assistance with.

This document is an addendum to my contracts which lists all equipment being sold as part of that contract. It has 2 sheets in it ("Addendum B" and "XREF"), and "Addendum B" has several dependent columns: Vendor, Manufacturer, Model, Description, and Price. Their dependencies are as follows:

Currently Working

  • Vendor: Basic data validation pulling from XREF!A2:A.

Not working, script in file

  • Manufacturer: Based on the Vendor selected, should be a drop-down list generated from the column headed with that vendor's name on "XREF".

Now here's were it gets tricky beyond what I had previously done.

  • Model: I want this column to be a drop-down listing all model numbers associated with that manufacturer, from a completely separate price list provided to me by my vendor. (I have shared a sample price list which reflects column positions as they appear in all such files.

  • Description: Displays the corresponding description for the Model selected, from the price list selected in the Vendor column.

  • Price: Displays the corresponding markup price for the Model selected, from the price list selected in the Vendor column.

And that about summarizes my goals and what I'm struggling with.

Andrew
  • 3
  • 1
  • 4
  • Final note, you will get a better response if you include your code and restrict yourself from asking multiple questions. Including code shows you put effort into the problem and asking just one/related question keeps the problem tractable. Also, prevents the question from getting closed for being too board. – Jack Brown Mar 15 '17 at 00:00

1 Answers1

0

So I looked into your script file in sheet Addendum B. I have made few edits and it should be working now, the modified code:

    function onEdit() 
{
  var ss = SpreadsheetApp.getActiveSpreadsheet(),
      sheet = ss.getActiveSheet(),
      name = sheet.getName();
  if (name != 'Addendum B') return;
  var range = sheet.getActiveRange(),
      col = range.getColumn();
  if (col != 6) return;  //You col was set to 5 changed it to 6!
  var val = range.getValue(),
      dv = ss.getSheetByName('XREF'),
      data = dv.getDataRange().getValues(),
      catCol = data[0].indexOf(val),
      list = [];
  Logger.log(catCol)
  for (var i = 1, len = 100; i < len; i++) // Problem is here, you have too many items in list! Cannot have more 500 items for validation
      list.push(data[i][catCol]);
  var listRange = dv.getRange(2,catCol +1,dv.getLastRow() - 1, 1)
  Logger.log(list)
  var cell = sheet.getRange(range.getRow(), col-1)
  var rule = SpreadsheetApp.newDataValidation()
  .requireValueInRange(listRange)   // Use requireValueIn Range instead to fix the problem
  .build();
  cell.setDataValidation(rule);
  Logger.log(cell.getRow())
}

The reason your validation was not working was you had more than 500 items in your data validation list. I just modified it to take the same values from range instead. Hope you find that helpful!

Now for the remaining 3 questions, here are my comments and thoughts on it:

1) I didn't find any code related to the problem you mentioned in your question. So, I am gonna assume you are asking for general ideas on how to achieve this?

2) You basically approach the problem the same as you did with the above code! Once a manufacturer is selected, the script looks for that manufacturer in the sheet and update the Data validation in the corresponding model column. You will modify the code like so

var ss = SpreadsheetApp.openById("1nbCJOkpIQxnn71sJPj6X4KaahROP5cMg1SI9xIeJdvY")
//The above code with select the catalog sheet.
dv = ss.getSheetByName('Misc_Catalog')
//The above code will open the Misc_Catalog tab. 

3) A better approach would be to use Sidebar/Dialog Box to validate your input then add it to the sheet at the end. (Looks Cleaner and also prevents unnecessary on edit trigger in the sheet, which can take a while to update.) You find more details here: https://developers.google.com/apps-script/guides/dialogs

Jack Brown
  • 5,802
  • 2
  • 12
  • 27
  • That's interesting. I'm not familiar with creating either of those. You're suggesting a dialog box that contains three drop-downs, and then on 'OK' it populates the row? – Andrew Mar 15 '17 at 03:33
  • Yes, exactly. The dropdown will get updated as you fill in the required details. – Jack Brown Mar 15 '17 at 03:36
  • So, I was just testing your fix, and it doesn't seem to be working completely. The Manufacturer drop-down is only showing the first 48 results. As for the dialog box/sidebar, could you give me an example of how I would stack all that code? I reviewed the link you provided at the end of your answer, and understand the general principals at work, but this is just outside my familiarity. – Andrew Mar 15 '17 at 03:55
  • Yeah was using the wrong sheet to get the last row. Modified it, it should work now. – Jack Brown Mar 15 '17 at 04:21
  • Thank you again for your invaluable assistance. I'm still unsure of how to write the second lookup. In a cell formula I would use '=arrayformula(vlookup(...))', but I don't know how to translate that into this scenario. The first drop-down was retrieving a defined list from a column, but the Model drop-down needs to find all values of colB where colA=MFR. – Andrew Mar 16 '17 at 21:55
  • You can use probably use =filter(). All the best. – Jack Brown Mar 16 '17 at 22:42
  • Sorry, maybe I was unclear. My problem is I'm not sure how to change the `var ListRange =` line to include the filter. Can I insert a CategoryFilter defined against my other spreadsheet, or do i need to define my data as a table and then filter the table, and feed that into the `listRange` argument? – Andrew Mar 17 '17 at 02:12
  • You will have to go through each value and pick out the values that you want. Then select the corresponding range, write a brief code to do the same with a sample dataset. Perfect it there, then include it to this code. Also please start a new thread if you have further questions and do include your code. That way more people will be able to assist you with that. Comments are not a good way to get answers or communicate in this forum. – Jack Brown Mar 17 '17 at 16:59