0

I'm trying to figure a way to add DataValidation with named range name as "Range" value. Using getRangeByName in requireValueInRange provides me with just "A1:A50" while i need to find a way to put "SampleRange" (which is range name) in it's place. It is possible to do manually but i have 300 rows to update one by one and i need a way to automate it.

function ValidationNamedRange() {
    var NameSpace = "SampleRange";
    var rule = SpreadsheetApp.newDataValidation().requireValueInRange(NameSpace).build();
    range.setDataValidation(rule);
  }
}

Thanks for the help!

3

1 Answer 1

0

GetRangeByName outputs the range as A1 notation

This is wrong. Besides the correct syntax is getRangeByName(), this method returns a Range object.

Example

The following will add a data validation to the specified named range.

  1. First create a named range, and set its name to NamedRange1
  2. Execute the following script

    function myFunction() {
      var name = 'NamedRange1';
      var rng = SpreadsheetApp.getActiveSpreadsheet().getRangeByName(name);
      var rule = SpreadsheetApp.newDataValidation().requireNumberBetween(5, 10).build();
      rng.setDataValidation(rule);
    }
    
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for answer. I guess i wasn't clear enough. I need to find a way to add a Named Range name as range value in validation. When i use "GetRangeByName(SampleRange)" I get data validation with "A3:B400" and I need a way to have "SampleRange" instead. Is there a way to create DataValidation rule that will work like this?
this adds dataValidation on a range, but the question is actually, how to add datavalidation that adds a dropdown verifying the content 'against' a named range it's easy enough to generate a range, but it will always translate to the A1 notation within the datavalidator as far as i know, I have not been able to do this either as of yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.