Lookup rows in every sheet then on match, jump to cell











up vote
1
down vote

favorite












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);
}

}









share|improve this question






















  • In your script, var ShtID = sheet.getSheetId() has no methods of getRange() and setActiveCell, because sheet.getSheetId() returns an integer value. And SchCell has no values. So in order to help to correctly understand your situation, can you provide the additional information? Are there several columns in each sheet you want to compare? If several columns are existing, which column of the last row do you want to compare with "A2" of sheet 4? And, I think that if you provide a sample spreadsheet, it will help users think of your solution.
    – Tanaike
    Nov 18 at 1:47










  • Spreadsheet link I'm just using a sample sheet & working with it as test. Using it for a registration form in my school. Which will have 4 columns in each sheet. Each sheet divided by classes. Column A will have names, column B will contain contact number, Column C & D will be a "Tick" or an "X". Which have yet to be created, but that's my plan. Comparing A2 of sheet 4 with Column B of every other sheet. A2 of sheet 4 will be the contact number I'll be filling to lookup every time
    – Tyler
    Nov 18 at 1:59












  • Thank you for replying and sharing a sample spreadsheet. In your reply, is sheet 4 Sheet5 of sheet name? About Comparing A2 of sheet 4 with Column B of every other sheet., in your sample spreadsheet, a sheet of Test2 has column B and "B1" is 4. In this case, do you want to compare this and 2 of "A2" of Sheet5? If the result of comparison is false, do nothing. If the result is true, you want to set the active cell to "B1" of Test2. Is my understanding correct?
    – Tanaike
    Nov 18 at 2:09










  • @Tanaike Thanks for getting back. Yes Sheet 4 refers to Sheet5. Bad naming. Was just testing to my own understanding. Yup. Exactly what you understood is what I want to do. Search column B of all sheets, if true jump to that sheet & cell, else continue with loop till it ends. If no result found, Displays no match
    – Tyler
    Nov 18 at 2:30










  • Thank you for replying. I posted an answer. Could you please confirm it? If I misunderstand your question, please tell me. I would like to modify it.
    – Tanaike
    Nov 18 at 7:02















up vote
1
down vote

favorite












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);
}

}









share|improve this question






















  • In your script, var ShtID = sheet.getSheetId() has no methods of getRange() and setActiveCell, because sheet.getSheetId() returns an integer value. And SchCell has no values. So in order to help to correctly understand your situation, can you provide the additional information? Are there several columns in each sheet you want to compare? If several columns are existing, which column of the last row do you want to compare with "A2" of sheet 4? And, I think that if you provide a sample spreadsheet, it will help users think of your solution.
    – Tanaike
    Nov 18 at 1:47










  • Spreadsheet link I'm just using a sample sheet & working with it as test. Using it for a registration form in my school. Which will have 4 columns in each sheet. Each sheet divided by classes. Column A will have names, column B will contain contact number, Column C & D will be a "Tick" or an "X". Which have yet to be created, but that's my plan. Comparing A2 of sheet 4 with Column B of every other sheet. A2 of sheet 4 will be the contact number I'll be filling to lookup every time
    – Tyler
    Nov 18 at 1:59












  • Thank you for replying and sharing a sample spreadsheet. In your reply, is sheet 4 Sheet5 of sheet name? About Comparing A2 of sheet 4 with Column B of every other sheet., in your sample spreadsheet, a sheet of Test2 has column B and "B1" is 4. In this case, do you want to compare this and 2 of "A2" of Sheet5? If the result of comparison is false, do nothing. If the result is true, you want to set the active cell to "B1" of Test2. Is my understanding correct?
    – Tanaike
    Nov 18 at 2:09










  • @Tanaike Thanks for getting back. Yes Sheet 4 refers to Sheet5. Bad naming. Was just testing to my own understanding. Yup. Exactly what you understood is what I want to do. Search column B of all sheets, if true jump to that sheet & cell, else continue with loop till it ends. If no result found, Displays no match
    – Tyler
    Nov 18 at 2:30










  • Thank you for replying. I posted an answer. Could you please confirm it? If I misunderstand your question, please tell me. I would like to modify it.
    – Tanaike
    Nov 18 at 7:02













up vote
1
down vote

favorite









up vote
1
down vote

favorite











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);
}

}









share|improve this question













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);
}

}






google-apps-script google-sheets google-sheets-api google-sheets-macros






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 18 at 1:22









Tyler

1261114




1261114












  • In your script, var ShtID = sheet.getSheetId() has no methods of getRange() and setActiveCell, because sheet.getSheetId() returns an integer value. And SchCell has no values. So in order to help to correctly understand your situation, can you provide the additional information? Are there several columns in each sheet you want to compare? If several columns are existing, which column of the last row do you want to compare with "A2" of sheet 4? And, I think that if you provide a sample spreadsheet, it will help users think of your solution.
    – Tanaike
    Nov 18 at 1:47










  • Spreadsheet link I'm just using a sample sheet & working with it as test. Using it for a registration form in my school. Which will have 4 columns in each sheet. Each sheet divided by classes. Column A will have names, column B will contain contact number, Column C & D will be a "Tick" or an "X". Which have yet to be created, but that's my plan. Comparing A2 of sheet 4 with Column B of every other sheet. A2 of sheet 4 will be the contact number I'll be filling to lookup every time
    – Tyler
    Nov 18 at 1:59












  • Thank you for replying and sharing a sample spreadsheet. In your reply, is sheet 4 Sheet5 of sheet name? About Comparing A2 of sheet 4 with Column B of every other sheet., in your sample spreadsheet, a sheet of Test2 has column B and "B1" is 4. In this case, do you want to compare this and 2 of "A2" of Sheet5? If the result of comparison is false, do nothing. If the result is true, you want to set the active cell to "B1" of Test2. Is my understanding correct?
    – Tanaike
    Nov 18 at 2:09










  • @Tanaike Thanks for getting back. Yes Sheet 4 refers to Sheet5. Bad naming. Was just testing to my own understanding. Yup. Exactly what you understood is what I want to do. Search column B of all sheets, if true jump to that sheet & cell, else continue with loop till it ends. If no result found, Displays no match
    – Tyler
    Nov 18 at 2:30










  • Thank you for replying. I posted an answer. Could you please confirm it? If I misunderstand your question, please tell me. I would like to modify it.
    – Tanaike
    Nov 18 at 7:02


















  • In your script, var ShtID = sheet.getSheetId() has no methods of getRange() and setActiveCell, because sheet.getSheetId() returns an integer value. And SchCell has no values. So in order to help to correctly understand your situation, can you provide the additional information? Are there several columns in each sheet you want to compare? If several columns are existing, which column of the last row do you want to compare with "A2" of sheet 4? And, I think that if you provide a sample spreadsheet, it will help users think of your solution.
    – Tanaike
    Nov 18 at 1:47










  • Spreadsheet link I'm just using a sample sheet & working with it as test. Using it for a registration form in my school. Which will have 4 columns in each sheet. Each sheet divided by classes. Column A will have names, column B will contain contact number, Column C & D will be a "Tick" or an "X". Which have yet to be created, but that's my plan. Comparing A2 of sheet 4 with Column B of every other sheet. A2 of sheet 4 will be the contact number I'll be filling to lookup every time
    – Tyler
    Nov 18 at 1:59












  • Thank you for replying and sharing a sample spreadsheet. In your reply, is sheet 4 Sheet5 of sheet name? About Comparing A2 of sheet 4 with Column B of every other sheet., in your sample spreadsheet, a sheet of Test2 has column B and "B1" is 4. In this case, do you want to compare this and 2 of "A2" of Sheet5? If the result of comparison is false, do nothing. If the result is true, you want to set the active cell to "B1" of Test2. Is my understanding correct?
    – Tanaike
    Nov 18 at 2:09










  • @Tanaike Thanks for getting back. Yes Sheet 4 refers to Sheet5. Bad naming. Was just testing to my own understanding. Yup. Exactly what you understood is what I want to do. Search column B of all sheets, if true jump to that sheet & cell, else continue with loop till it ends. If no result found, Displays no match
    – Tyler
    Nov 18 at 2:30










  • Thank you for replying. I posted an answer. Could you please confirm it? If I misunderstand your question, please tell me. I would like to modify it.
    – Tanaike
    Nov 18 at 7:02
















In your script, var ShtID = sheet.getSheetId() has no methods of getRange() and setActiveCell, because sheet.getSheetId() returns an integer value. And SchCell has no values. So in order to help to correctly understand your situation, can you provide the additional information? Are there several columns in each sheet you want to compare? If several columns are existing, which column of the last row do you want to compare with "A2" of sheet 4? And, I think that if you provide a sample spreadsheet, it will help users think of your solution.
– Tanaike
Nov 18 at 1:47




In your script, var ShtID = sheet.getSheetId() has no methods of getRange() and setActiveCell, because sheet.getSheetId() returns an integer value. And SchCell has no values. So in order to help to correctly understand your situation, can you provide the additional information? Are there several columns in each sheet you want to compare? If several columns are existing, which column of the last row do you want to compare with "A2" of sheet 4? And, I think that if you provide a sample spreadsheet, it will help users think of your solution.
– Tanaike
Nov 18 at 1:47












Spreadsheet link I'm just using a sample sheet & working with it as test. Using it for a registration form in my school. Which will have 4 columns in each sheet. Each sheet divided by classes. Column A will have names, column B will contain contact number, Column C & D will be a "Tick" or an "X". Which have yet to be created, but that's my plan. Comparing A2 of sheet 4 with Column B of every other sheet. A2 of sheet 4 will be the contact number I'll be filling to lookup every time
– Tyler
Nov 18 at 1:59






Spreadsheet link I'm just using a sample sheet & working with it as test. Using it for a registration form in my school. Which will have 4 columns in each sheet. Each sheet divided by classes. Column A will have names, column B will contain contact number, Column C & D will be a "Tick" or an "X". Which have yet to be created, but that's my plan. Comparing A2 of sheet 4 with Column B of every other sheet. A2 of sheet 4 will be the contact number I'll be filling to lookup every time
– Tyler
Nov 18 at 1:59














Thank you for replying and sharing a sample spreadsheet. In your reply, is sheet 4 Sheet5 of sheet name? About Comparing A2 of sheet 4 with Column B of every other sheet., in your sample spreadsheet, a sheet of Test2 has column B and "B1" is 4. In this case, do you want to compare this and 2 of "A2" of Sheet5? If the result of comparison is false, do nothing. If the result is true, you want to set the active cell to "B1" of Test2. Is my understanding correct?
– Tanaike
Nov 18 at 2:09




Thank you for replying and sharing a sample spreadsheet. In your reply, is sheet 4 Sheet5 of sheet name? About Comparing A2 of sheet 4 with Column B of every other sheet., in your sample spreadsheet, a sheet of Test2 has column B and "B1" is 4. In this case, do you want to compare this and 2 of "A2" of Sheet5? If the result of comparison is false, do nothing. If the result is true, you want to set the active cell to "B1" of Test2. Is my understanding correct?
– Tanaike
Nov 18 at 2:09












@Tanaike Thanks for getting back. Yes Sheet 4 refers to Sheet5. Bad naming. Was just testing to my own understanding. Yup. Exactly what you understood is what I want to do. Search column B of all sheets, if true jump to that sheet & cell, else continue with loop till it ends. If no result found, Displays no match
– Tyler
Nov 18 at 2:30




@Tanaike Thanks for getting back. Yes Sheet 4 refers to Sheet5. Bad naming. Was just testing to my own understanding. Yup. Exactly what you understood is what I want to do. Search column B of all sheets, if true jump to that sheet & cell, else continue with loop till it ends. If no result found, Displays no match
– Tyler
Nov 18 at 2:30












Thank you for replying. I posted an answer. Could you please confirm it? If I misunderstand your question, please tell me. I would like to modify it.
– Tanaike
Nov 18 at 7:02




Thank you for replying. I posted an answer. Could you please confirm it? If I misunderstand your question, please tell me. I would like to modify it.
– Tanaike
Nov 18 at 7:02












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted











  • You want to compare "A2" of the sheet ("Sheet5") of index 3 with the value of last row of column "B" for each sheet except for "Sheet5".

  • When the value of "A2" of "Sheet5" is the same with the last row of column "B", you want to activate the cell.


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 of getRange() and setActiveCell, because sheet.getSheetId() returns an integer value.


  • SchCell has no values.

  • At for ( j = 1 ; j >= lastRow; j++){, this for loop doesn't loop.


Modified script:



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]);

// Modified part
var allsheets = ss.getSheets();
for (var s = 0; s < allsheets.length; s++) {
var sheet = allsheets[s];
if (s != 3) {
var values = sheet.getRange("B1:B").getValues().filter(String); // Retrieve values of column B
if (values.length > 0) {
var v = values[values.length - 1][0]; // Value of last row of column B
var lastRow = "B" + values.length; // Last row of column B
if (v == CValue[0][0]) {
sheet.getRange(lastRow).activate();
return true;
}
}
}
};
}


Note:




  • In this modified script, when the value which is the same with "A2" of "Sheet5" is found, the cell of the first sheet is activated and focused.


    • In the current stage, several cells of each sheet cannot be activated and focused simultaneously.




References:




  • getSheetId()

  • activate()


Edit:




  • You want to active all cells of column "B" in the first sheet when the cells matched to "A2" of "Sheet5" are found.


If my understanding is correct, how about this? Please modify the modified part to the following script.



// Modified part
var allsheets = ss.getSheets();
for (var s = 0; s < allsheets.length; s++) {
var sheet = allsheets[s];
if (s != 3) {
var values = sheet.getRange("B1:B").getValues().filter(String);
if (values.length > 0) {
var ranges = values.reduce(function(ar, e, i) {
if (e[0] == CValue[0][0]) {
ar.push("B" + (i + 1));
}
return ar;
}, );
if (ranges.length > 0) {
Logger.log(ranges)
sheet.setActiveRangeList(sheet.getRangeList(ranges));
break;
}
}
}
};





share|improve this answer























  • Thanks for the edit. It does work but is not what I want. Is not just to compare with last row. I want it to loop through all cells in column B, once found. Cell is activated
    – Tyler
    Nov 18 at 7:13






  • 1




    @Tyler I'm really sorry for my poor English skill. I cannot understand what you want to do. You want to select all cells which are the same value of "A2" of "Sheet5". Is my understanding correct?
    – Tanaike
    Nov 18 at 7:23






  • 1




    @tanike Is okay. I appreciate the help you're giving. Let me try to explain better. I want to compare the value of A2, in Sheet5. With all values in column B of other sheets. Once it match. Sheet and Cell is activated. Is that easier to understand?
    – Tyler
    Nov 18 at 7:29






  • 1




    @Tyler Thank you for replying. I'm really sorry for the inconvenience. I updated my answer. Could you please confirm it?
    – Tanaike
    Nov 18 at 7:49






  • 1




    You did it! Thanks so much. No inconvenience at all. Really thankful for the help
    – Tyler
    Nov 18 at 7:59











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357102%2flookup-rows-in-every-sheet-then-on-match-jump-to-cell%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted











  • You want to compare "A2" of the sheet ("Sheet5") of index 3 with the value of last row of column "B" for each sheet except for "Sheet5".

  • When the value of "A2" of "Sheet5" is the same with the last row of column "B", you want to activate the cell.


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 of getRange() and setActiveCell, because sheet.getSheetId() returns an integer value.


  • SchCell has no values.

  • At for ( j = 1 ; j >= lastRow; j++){, this for loop doesn't loop.


Modified script:



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]);

// Modified part
var allsheets = ss.getSheets();
for (var s = 0; s < allsheets.length; s++) {
var sheet = allsheets[s];
if (s != 3) {
var values = sheet.getRange("B1:B").getValues().filter(String); // Retrieve values of column B
if (values.length > 0) {
var v = values[values.length - 1][0]; // Value of last row of column B
var lastRow = "B" + values.length; // Last row of column B
if (v == CValue[0][0]) {
sheet.getRange(lastRow).activate();
return true;
}
}
}
};
}


Note:




  • In this modified script, when the value which is the same with "A2" of "Sheet5" is found, the cell of the first sheet is activated and focused.


    • In the current stage, several cells of each sheet cannot be activated and focused simultaneously.




References:




  • getSheetId()

  • activate()


Edit:




  • You want to active all cells of column "B" in the first sheet when the cells matched to "A2" of "Sheet5" are found.


If my understanding is correct, how about this? Please modify the modified part to the following script.



// Modified part
var allsheets = ss.getSheets();
for (var s = 0; s < allsheets.length; s++) {
var sheet = allsheets[s];
if (s != 3) {
var values = sheet.getRange("B1:B").getValues().filter(String);
if (values.length > 0) {
var ranges = values.reduce(function(ar, e, i) {
if (e[0] == CValue[0][0]) {
ar.push("B" + (i + 1));
}
return ar;
}, );
if (ranges.length > 0) {
Logger.log(ranges)
sheet.setActiveRangeList(sheet.getRangeList(ranges));
break;
}
}
}
};





share|improve this answer























  • Thanks for the edit. It does work but is not what I want. Is not just to compare with last row. I want it to loop through all cells in column B, once found. Cell is activated
    – Tyler
    Nov 18 at 7:13






  • 1




    @Tyler I'm really sorry for my poor English skill. I cannot understand what you want to do. You want to select all cells which are the same value of "A2" of "Sheet5". Is my understanding correct?
    – Tanaike
    Nov 18 at 7:23






  • 1




    @tanike Is okay. I appreciate the help you're giving. Let me try to explain better. I want to compare the value of A2, in Sheet5. With all values in column B of other sheets. Once it match. Sheet and Cell is activated. Is that easier to understand?
    – Tyler
    Nov 18 at 7:29






  • 1




    @Tyler Thank you for replying. I'm really sorry for the inconvenience. I updated my answer. Could you please confirm it?
    – Tanaike
    Nov 18 at 7:49






  • 1




    You did it! Thanks so much. No inconvenience at all. Really thankful for the help
    – Tyler
    Nov 18 at 7:59















up vote
1
down vote



accepted











  • You want to compare "A2" of the sheet ("Sheet5") of index 3 with the value of last row of column "B" for each sheet except for "Sheet5".

  • When the value of "A2" of "Sheet5" is the same with the last row of column "B", you want to activate the cell.


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 of getRange() and setActiveCell, because sheet.getSheetId() returns an integer value.


  • SchCell has no values.

  • At for ( j = 1 ; j >= lastRow; j++){, this for loop doesn't loop.


Modified script:



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]);

// Modified part
var allsheets = ss.getSheets();
for (var s = 0; s < allsheets.length; s++) {
var sheet = allsheets[s];
if (s != 3) {
var values = sheet.getRange("B1:B").getValues().filter(String); // Retrieve values of column B
if (values.length > 0) {
var v = values[values.length - 1][0]; // Value of last row of column B
var lastRow = "B" + values.length; // Last row of column B
if (v == CValue[0][0]) {
sheet.getRange(lastRow).activate();
return true;
}
}
}
};
}


Note:




  • In this modified script, when the value which is the same with "A2" of "Sheet5" is found, the cell of the first sheet is activated and focused.


    • In the current stage, several cells of each sheet cannot be activated and focused simultaneously.




References:




  • getSheetId()

  • activate()


Edit:




  • You want to active all cells of column "B" in the first sheet when the cells matched to "A2" of "Sheet5" are found.


If my understanding is correct, how about this? Please modify the modified part to the following script.



// Modified part
var allsheets = ss.getSheets();
for (var s = 0; s < allsheets.length; s++) {
var sheet = allsheets[s];
if (s != 3) {
var values = sheet.getRange("B1:B").getValues().filter(String);
if (values.length > 0) {
var ranges = values.reduce(function(ar, e, i) {
if (e[0] == CValue[0][0]) {
ar.push("B" + (i + 1));
}
return ar;
}, );
if (ranges.length > 0) {
Logger.log(ranges)
sheet.setActiveRangeList(sheet.getRangeList(ranges));
break;
}
}
}
};





share|improve this answer























  • Thanks for the edit. It does work but is not what I want. Is not just to compare with last row. I want it to loop through all cells in column B, once found. Cell is activated
    – Tyler
    Nov 18 at 7:13






  • 1




    @Tyler I'm really sorry for my poor English skill. I cannot understand what you want to do. You want to select all cells which are the same value of "A2" of "Sheet5". Is my understanding correct?
    – Tanaike
    Nov 18 at 7:23






  • 1




    @tanike Is okay. I appreciate the help you're giving. Let me try to explain better. I want to compare the value of A2, in Sheet5. With all values in column B of other sheets. Once it match. Sheet and Cell is activated. Is that easier to understand?
    – Tyler
    Nov 18 at 7:29






  • 1




    @Tyler Thank you for replying. I'm really sorry for the inconvenience. I updated my answer. Could you please confirm it?
    – Tanaike
    Nov 18 at 7:49






  • 1




    You did it! Thanks so much. No inconvenience at all. Really thankful for the help
    – Tyler
    Nov 18 at 7:59













up vote
1
down vote



accepted







up vote
1
down vote



accepted







  • You want to compare "A2" of the sheet ("Sheet5") of index 3 with the value of last row of column "B" for each sheet except for "Sheet5".

  • When the value of "A2" of "Sheet5" is the same with the last row of column "B", you want to activate the cell.


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 of getRange() and setActiveCell, because sheet.getSheetId() returns an integer value.


  • SchCell has no values.

  • At for ( j = 1 ; j >= lastRow; j++){, this for loop doesn't loop.


Modified script:



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]);

// Modified part
var allsheets = ss.getSheets();
for (var s = 0; s < allsheets.length; s++) {
var sheet = allsheets[s];
if (s != 3) {
var values = sheet.getRange("B1:B").getValues().filter(String); // Retrieve values of column B
if (values.length > 0) {
var v = values[values.length - 1][0]; // Value of last row of column B
var lastRow = "B" + values.length; // Last row of column B
if (v == CValue[0][0]) {
sheet.getRange(lastRow).activate();
return true;
}
}
}
};
}


Note:




  • In this modified script, when the value which is the same with "A2" of "Sheet5" is found, the cell of the first sheet is activated and focused.


    • In the current stage, several cells of each sheet cannot be activated and focused simultaneously.




References:




  • getSheetId()

  • activate()


Edit:




  • You want to active all cells of column "B" in the first sheet when the cells matched to "A2" of "Sheet5" are found.


If my understanding is correct, how about this? Please modify the modified part to the following script.



// Modified part
var allsheets = ss.getSheets();
for (var s = 0; s < allsheets.length; s++) {
var sheet = allsheets[s];
if (s != 3) {
var values = sheet.getRange("B1:B").getValues().filter(String);
if (values.length > 0) {
var ranges = values.reduce(function(ar, e, i) {
if (e[0] == CValue[0][0]) {
ar.push("B" + (i + 1));
}
return ar;
}, );
if (ranges.length > 0) {
Logger.log(ranges)
sheet.setActiveRangeList(sheet.getRangeList(ranges));
break;
}
}
}
};





share|improve this answer















  • You want to compare "A2" of the sheet ("Sheet5") of index 3 with the value of last row of column "B" for each sheet except for "Sheet5".

  • When the value of "A2" of "Sheet5" is the same with the last row of column "B", you want to activate the cell.


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 of getRange() and setActiveCell, because sheet.getSheetId() returns an integer value.


  • SchCell has no values.

  • At for ( j = 1 ; j >= lastRow; j++){, this for loop doesn't loop.


Modified script:



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]);

// Modified part
var allsheets = ss.getSheets();
for (var s = 0; s < allsheets.length; s++) {
var sheet = allsheets[s];
if (s != 3) {
var values = sheet.getRange("B1:B").getValues().filter(String); // Retrieve values of column B
if (values.length > 0) {
var v = values[values.length - 1][0]; // Value of last row of column B
var lastRow = "B" + values.length; // Last row of column B
if (v == CValue[0][0]) {
sheet.getRange(lastRow).activate();
return true;
}
}
}
};
}


Note:




  • In this modified script, when the value which is the same with "A2" of "Sheet5" is found, the cell of the first sheet is activated and focused.


    • In the current stage, several cells of each sheet cannot be activated and focused simultaneously.




References:




  • getSheetId()

  • activate()


Edit:




  • You want to active all cells of column "B" in the first sheet when the cells matched to "A2" of "Sheet5" are found.


If my understanding is correct, how about this? Please modify the modified part to the following script.



// Modified part
var allsheets = ss.getSheets();
for (var s = 0; s < allsheets.length; s++) {
var sheet = allsheets[s];
if (s != 3) {
var values = sheet.getRange("B1:B").getValues().filter(String);
if (values.length > 0) {
var ranges = values.reduce(function(ar, e, i) {
if (e[0] == CValue[0][0]) {
ar.push("B" + (i + 1));
}
return ar;
}, );
if (ranges.length > 0) {
Logger.log(ranges)
sheet.setActiveRangeList(sheet.getRangeList(ranges));
break;
}
}
}
};






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 18 at 7:49

























answered Nov 18 at 7:02









Tanaike

18.5k2921




18.5k2921












  • Thanks for the edit. It does work but is not what I want. Is not just to compare with last row. I want it to loop through all cells in column B, once found. Cell is activated
    – Tyler
    Nov 18 at 7:13






  • 1




    @Tyler I'm really sorry for my poor English skill. I cannot understand what you want to do. You want to select all cells which are the same value of "A2" of "Sheet5". Is my understanding correct?
    – Tanaike
    Nov 18 at 7:23






  • 1




    @tanike Is okay. I appreciate the help you're giving. Let me try to explain better. I want to compare the value of A2, in Sheet5. With all values in column B of other sheets. Once it match. Sheet and Cell is activated. Is that easier to understand?
    – Tyler
    Nov 18 at 7:29






  • 1




    @Tyler Thank you for replying. I'm really sorry for the inconvenience. I updated my answer. Could you please confirm it?
    – Tanaike
    Nov 18 at 7:49






  • 1




    You did it! Thanks so much. No inconvenience at all. Really thankful for the help
    – Tyler
    Nov 18 at 7:59


















  • Thanks for the edit. It does work but is not what I want. Is not just to compare with last row. I want it to loop through all cells in column B, once found. Cell is activated
    – Tyler
    Nov 18 at 7:13






  • 1




    @Tyler I'm really sorry for my poor English skill. I cannot understand what you want to do. You want to select all cells which are the same value of "A2" of "Sheet5". Is my understanding correct?
    – Tanaike
    Nov 18 at 7:23






  • 1




    @tanike Is okay. I appreciate the help you're giving. Let me try to explain better. I want to compare the value of A2, in Sheet5. With all values in column B of other sheets. Once it match. Sheet and Cell is activated. Is that easier to understand?
    – Tyler
    Nov 18 at 7:29






  • 1




    @Tyler Thank you for replying. I'm really sorry for the inconvenience. I updated my answer. Could you please confirm it?
    – Tanaike
    Nov 18 at 7:49






  • 1




    You did it! Thanks so much. No inconvenience at all. Really thankful for the help
    – Tyler
    Nov 18 at 7:59
















Thanks for the edit. It does work but is not what I want. Is not just to compare with last row. I want it to loop through all cells in column B, once found. Cell is activated
– Tyler
Nov 18 at 7:13




Thanks for the edit. It does work but is not what I want. Is not just to compare with last row. I want it to loop through all cells in column B, once found. Cell is activated
– Tyler
Nov 18 at 7:13




1




1




@Tyler I'm really sorry for my poor English skill. I cannot understand what you want to do. You want to select all cells which are the same value of "A2" of "Sheet5". Is my understanding correct?
– Tanaike
Nov 18 at 7:23




@Tyler I'm really sorry for my poor English skill. I cannot understand what you want to do. You want to select all cells which are the same value of "A2" of "Sheet5". Is my understanding correct?
– Tanaike
Nov 18 at 7:23




1




1




@tanike Is okay. I appreciate the help you're giving. Let me try to explain better. I want to compare the value of A2, in Sheet5. With all values in column B of other sheets. Once it match. Sheet and Cell is activated. Is that easier to understand?
– Tyler
Nov 18 at 7:29




@tanike Is okay. I appreciate the help you're giving. Let me try to explain better. I want to compare the value of A2, in Sheet5. With all values in column B of other sheets. Once it match. Sheet and Cell is activated. Is that easier to understand?
– Tyler
Nov 18 at 7:29




1




1




@Tyler Thank you for replying. I'm really sorry for the inconvenience. I updated my answer. Could you please confirm it?
– Tanaike
Nov 18 at 7:49




@Tyler Thank you for replying. I'm really sorry for the inconvenience. I updated my answer. Could you please confirm it?
– Tanaike
Nov 18 at 7:49




1




1




You did it! Thanks so much. No inconvenience at all. Really thankful for the help
– Tyler
Nov 18 at 7:59




You did it! Thanks so much. No inconvenience at all. Really thankful for the help
– Tyler
Nov 18 at 7:59


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357102%2flookup-rows-in-every-sheet-then-on-match-jump-to-cell%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin