I have 2 columns which are user name and user telephone number in google sheet. I have a variable to store the input user name and I want to find the phone number of that user name whenever I change the input user name. Very appreciate your help.
function Showtel(){
var app = SpreadsheetApp;
var ss = app.getActiveSpreadsheet();
var ActiveSheet = ss.getActiveSheet();
var searchSheet = ss.getSheetByName('Sheet1');
You can use a trigger called onEdit that runs a function every time the user edits the sheet.
Here is the sample code provided by the docs
The
e
parameter is an Event Object which contains some data about the edit done by the user, which includes the range (which is the user name cell that changed).You can use this information to reference the range that contains the telephone number via the
offset
method. Then you can get the value of the cell viagetValue
method.In short, assuming the phone number is one column to the right of the name, the code would look similar to this: