get a Range by using getR(2,“firstname”)





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I would like to address the cells via the headline name.
for example. getR(sheet, 2,"firstname")



example data:



1: firstname, lastname

2: john, berg

3: mark, tost



I expect the following:



getR(sheet, 2,"firstname")
should then give me :
sheet.getRange(2, 1)



Maybe there is a possibility to make it write:
sheet.getR(2,"firstname") ?



I see the following advantages:
it is easier to understand and if the layout of the headings is reversed, it still works.



my prototype:



function getR(sheet, name) { // https://gist.github.com/printminion/5520691

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet);
var range = ss.getRange(1, 1, 1, ss.getMaxColumns()).getValues()[0];
Logger.log(range);
for (var row in range) {
Logger.log(range[row ]);
if ( range[row ] == name ) {
return parseInt(row ) + 1;
}
}
throw 'failed';
}









share|improve this question























  • What is supposed to represent 2in getR(sheet, 2,"firstname") what is the desired return result. An index? a string?

    – JSmith
    Nov 26 '18 at 19:22











  • Ok. What's wrong with your code?

    – TheMaster
    Nov 26 '18 at 20:48


















0















I would like to address the cells via the headline name.
for example. getR(sheet, 2,"firstname")



example data:



1: firstname, lastname

2: john, berg

3: mark, tost



I expect the following:



getR(sheet, 2,"firstname")
should then give me :
sheet.getRange(2, 1)



Maybe there is a possibility to make it write:
sheet.getR(2,"firstname") ?



I see the following advantages:
it is easier to understand and if the layout of the headings is reversed, it still works.



my prototype:



function getR(sheet, name) { // https://gist.github.com/printminion/5520691

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet);
var range = ss.getRange(1, 1, 1, ss.getMaxColumns()).getValues()[0];
Logger.log(range);
for (var row in range) {
Logger.log(range[row ]);
if ( range[row ] == name ) {
return parseInt(row ) + 1;
}
}
throw 'failed';
}









share|improve this question























  • What is supposed to represent 2in getR(sheet, 2,"firstname") what is the desired return result. An index? a string?

    – JSmith
    Nov 26 '18 at 19:22











  • Ok. What's wrong with your code?

    – TheMaster
    Nov 26 '18 at 20:48














0












0








0








I would like to address the cells via the headline name.
for example. getR(sheet, 2,"firstname")



example data:



1: firstname, lastname

2: john, berg

3: mark, tost



I expect the following:



getR(sheet, 2,"firstname")
should then give me :
sheet.getRange(2, 1)



Maybe there is a possibility to make it write:
sheet.getR(2,"firstname") ?



I see the following advantages:
it is easier to understand and if the layout of the headings is reversed, it still works.



my prototype:



function getR(sheet, name) { // https://gist.github.com/printminion/5520691

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet);
var range = ss.getRange(1, 1, 1, ss.getMaxColumns()).getValues()[0];
Logger.log(range);
for (var row in range) {
Logger.log(range[row ]);
if ( range[row ] == name ) {
return parseInt(row ) + 1;
}
}
throw 'failed';
}









share|improve this question














I would like to address the cells via the headline name.
for example. getR(sheet, 2,"firstname")



example data:



1: firstname, lastname

2: john, berg

3: mark, tost



I expect the following:



getR(sheet, 2,"firstname")
should then give me :
sheet.getRange(2, 1)



Maybe there is a possibility to make it write:
sheet.getR(2,"firstname") ?



I see the following advantages:
it is easier to understand and if the layout of the headings is reversed, it still works.



my prototype:



function getR(sheet, name) { // https://gist.github.com/printminion/5520691

var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet);
var range = ss.getRange(1, 1, 1, ss.getMaxColumns()).getValues()[0];
Logger.log(range);
for (var row in range) {
Logger.log(range[row ]);
if ( range[row ] == name ) {
return parseInt(row ) + 1;
}
}
throw 'failed';
}






google-apps-script






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 18:44









SL5netSL5net

3801416




3801416













  • What is supposed to represent 2in getR(sheet, 2,"firstname") what is the desired return result. An index? a string?

    – JSmith
    Nov 26 '18 at 19:22











  • Ok. What's wrong with your code?

    – TheMaster
    Nov 26 '18 at 20:48



















  • What is supposed to represent 2in getR(sheet, 2,"firstname") what is the desired return result. An index? a string?

    – JSmith
    Nov 26 '18 at 19:22











  • Ok. What's wrong with your code?

    – TheMaster
    Nov 26 '18 at 20:48

















What is supposed to represent 2in getR(sheet, 2,"firstname") what is the desired return result. An index? a string?

– JSmith
Nov 26 '18 at 19:22





What is supposed to represent 2in getR(sheet, 2,"firstname") what is the desired return result. An index? a string?

– JSmith
Nov 26 '18 at 19:22













Ok. What's wrong with your code?

– TheMaster
Nov 26 '18 at 20:48





Ok. What's wrong with your code?

– TheMaster
Nov 26 '18 at 20:48












1 Answer
1






active

oldest

votes


















1














Try this:



function getR(row,sheet,headername){
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName(sheet);
var rg=sh.getDataRange();
var nA=rg.getValues();
for(var i=1;i<nA.length;i++){
if(i+1==row){
for(var j=0;j<nA[i].length;j++){
if(nA[0][j]==headername){
return nA[i][j];
}
}
}
}
throw 'failed';
}





share|improve this answer
























  • works. i get the first entry in column firstname with: var range = getR(2,'Addresses','firstname'); Browser.msgBox(range);

    – SL5net
    Nov 26 '18 at 22:14














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',
autoActivateHeartbeat: false,
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%2f53487214%2fget-a-range-by-using-getr2-firstname%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









1














Try this:



function getR(row,sheet,headername){
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName(sheet);
var rg=sh.getDataRange();
var nA=rg.getValues();
for(var i=1;i<nA.length;i++){
if(i+1==row){
for(var j=0;j<nA[i].length;j++){
if(nA[0][j]==headername){
return nA[i][j];
}
}
}
}
throw 'failed';
}





share|improve this answer
























  • works. i get the first entry in column firstname with: var range = getR(2,'Addresses','firstname'); Browser.msgBox(range);

    – SL5net
    Nov 26 '18 at 22:14


















1














Try this:



function getR(row,sheet,headername){
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName(sheet);
var rg=sh.getDataRange();
var nA=rg.getValues();
for(var i=1;i<nA.length;i++){
if(i+1==row){
for(var j=0;j<nA[i].length;j++){
if(nA[0][j]==headername){
return nA[i][j];
}
}
}
}
throw 'failed';
}





share|improve this answer
























  • works. i get the first entry in column firstname with: var range = getR(2,'Addresses','firstname'); Browser.msgBox(range);

    – SL5net
    Nov 26 '18 at 22:14
















1












1








1







Try this:



function getR(row,sheet,headername){
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName(sheet);
var rg=sh.getDataRange();
var nA=rg.getValues();
for(var i=1;i<nA.length;i++){
if(i+1==row){
for(var j=0;j<nA[i].length;j++){
if(nA[0][j]==headername){
return nA[i][j];
}
}
}
}
throw 'failed';
}





share|improve this answer













Try this:



function getR(row,sheet,headername){
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName(sheet);
var rg=sh.getDataRange();
var nA=rg.getValues();
for(var i=1;i<nA.length;i++){
if(i+1==row){
for(var j=0;j<nA[i].length;j++){
if(nA[0][j]==headername){
return nA[i][j];
}
}
}
}
throw 'failed';
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 20:05









CooperCooper

8,3872829




8,3872829













  • works. i get the first entry in column firstname with: var range = getR(2,'Addresses','firstname'); Browser.msgBox(range);

    – SL5net
    Nov 26 '18 at 22:14





















  • works. i get the first entry in column firstname with: var range = getR(2,'Addresses','firstname'); Browser.msgBox(range);

    – SL5net
    Nov 26 '18 at 22:14



















works. i get the first entry in column firstname with: var range = getR(2,'Addresses','firstname'); Browser.msgBox(range);

– SL5net
Nov 26 '18 at 22:14







works. i get the first entry in column firstname with: var range = getR(2,'Addresses','firstname'); Browser.msgBox(range);

– SL5net
Nov 26 '18 at 22:14






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53487214%2fget-a-range-by-using-getr2-firstname%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

To store a contact into the json file from server.js file using a class in NodeJS

Redirect URL with Chrome Remote Debugging Android Devices

Dieringhausen