I've created a vlookup function to retrieve values in a Named Range, as it is part of an equation that's rather complicated to use in the sheet. It's structured just the same as the native VLOOKUP, but I only use it for Named Ranges.
Getting "TypeError: range.getValues is not a function" when I run a test, haven't been able to determine why. Any advice would be appreciated. MTIA
function c_test(){
var result = c_VLookup(25, "Foil_Cant_Values", 2);
Logger.log("c_VLookup returned: " + result);
}
function c_VLookup(searchKey, NamedRange, index) {
// Author: Max Hugen
// Date: 20102-11-21
// Purpose: Script version of sheets VLOOKUP(search_key, range, index)
var range = c_GetRangeByName(NamedRange);
if (!range) {
Logger.log("c_VLookup didn't return a range.");
return;
}
Logger.log("c_VLookup range: " + range);
//Logger returned: c_VLookup range: A160:E162
//TypeError: range.getValues is not a function (line 26, file "Utils")
var data = range.getValues();
var resultRow = data.filter( function(row) { row[1] = searchKey; });
var result = resultRow[index];
return result;
}
function c_GetRangeByName(NamedRange) {
SpreadsheetApp.getActiveSpreadsheet().getRangeByName(NamedRange).getA1Notation();
}
var data = range.getValues(), fromLogger returned: c_VLookup range: A160:E162, it seems that the range is the string value. So in this case, how about modifying the function ofc_GetRangeByName(NamedRange)? Because in this case, I think that it is required to know the information of Spreadsheet and sheet for the range. For example, ifvar range = SpreadsheetApp.getActiveSpreadsheet().getRangeByName(NamedRange)cannot be used instead ofvar range = c_GetRangeByName(NamedRange), can you provide the script ofc_GetRangeByName(NamedRange)?