Am trying to get the script to search for a value in sheet 4, range "A2" of the spreadsheet in the rest of the sheets then on match. It jumps to that sheet & row
Got my code working to loop through all sheets & get last row in each sheet. However the if function & jumping to matched cell ain't working.
Appreciate all the help I can get (:
First time using google sheets...
function Lookup() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
//Get Sheet
var sheet = ss.getSheets()[3];
//set row & column
var GCell = sheet.getRange(2, 1);
// read values from set row & column
var CValue = GCell.getValues();
Logger.log(CValue[0][0]);
//Loop all sheets
var allsheets = ss.getSheets();
for (var s in allsheets){
var sheet=allsheets[s]
//Get last row in each sheet
var ShtID = sheet.getSheetId();
var lastRow = sheet.getLastRow();
//var range = sheet.getRange("B2");
//Logger.log(range.getRowIndex());
var SchCell;
for ( j = 1 ; j >= lastRow; j++){
if(SchCell[j][1] === CValue){
var Crow = SchCell.getRowIndex();
ShtID.setActiveCell(ShtID.getRange(Crow, 1));
Logger.log("Matched Row =" +Crow);
return;
}
}
Logger.log("Last Row" + lastRow);
}
}
I understood what you want as above. If my understanding is correct, how about this modification? I think that there are several answers for your situation. So please think of this as one of them.
Modification points:
var ShtID = sheet.getSheetId()
has no methods ofgetRange()
andsetActiveCell
, becausesheet.getSheetId()
returns an integer value.SchCell
has no values.for ( j = 1 ; j >= lastRow; j++){
, this for loop doesn't loop.Modified script:
Note:
References:
Edit:
If my understanding is correct, how about this? Please modify the modified part to the following script.