我有一个房地产办公室,它使用google显示地址、买方名称、房地产经纪人名称和卖家名称。对于房地产经纪人名称列,我创建了一个下拉列表,以便他们可以从名称列表中进行选择。我需要做的是能够更新列表范围时,一个新的名称被输入到下拉列表。例如,如果一个新的房地产经纪人列出了一个属性,并且他们的名字不在列表中,那么输入信息的人只需在下拉列表中输入它,列表就会自动更新。谢谢
发布于 2022-05-12 22:12:09
使用下面的脚本,如果名称未在下拉列表中列出,则用户可以在下拉列表中输入其名称,这将将名称添加到名称列表中。
function script2(e) {
var s = SpreadsheetApp.getActiveSpreadsheet();
var sht1 = s.getSheetByName('2022'); //sheet where you have the dropdown
var sht2 = s.getSheetByName('Realtors'); //sheet where you have the list of names
var range = sht2.getRange('A:A'); //range for the list of names
var columnP = 16;
var columnQ = 17;
//get value of active cell if active cell is within columns P or Q
if (e.range.getColumn() === columnP || e.range.getColumn() === columnQ){
var cellValue = sht1.getActiveCell().getValue();
var result = hasValue(range, cellValue);
}
//if value is not found then it will add name to the list
if (result == false){
sht2.getRange('A2').getNextDataCell(SpreadsheetApp.Direction.DOWN).offset(1,0).setValue(cellValue);
}
else{
}
}
//this function searchs a value in a range
function hasValue(range, value) {
return range.getValues().flat().includes(value);
}https://stackoverflow.com/questions/72191810
复制相似问题