0

I'm sure there is a simple way to do this but I'm spinning wheels trying to figure it out. I have several columns, each of different lengths. I would like to get the A1 notation for each of them, minus a header. I get the index number of the column and then I want to get a range that includes all values under the header. What is the best way to go about this? Probably a trivial solution but thanks for help.

function get_range(header) {
    var data = s.getDataRange().getValues();
    var row = data[0];
    for( i in row){
        if (row[i] == header) {
            var colinx = parseInt(i)+1;
            var range = s.getRange(2,colinx,);
            var notation = range.getA1Notation();
Logger.log(notation);
        }
    }
}
RossV
  • 195
  • 3
  • 12
  • Why do you need the A1 notation? Will you use somewhere else or just to get the values? Also why do you need a collumn at a time? It's usually good practice to use getDataRange().getValues(); or getSheetValues(1, 1, -1, -1);. – Kriggs Jan 05 '15 at 23:14
  • The columns contain email addresses. Each column has a Named Range and I have scripts that will grab these named ranges. Additionally, I have a script for this spreadsheet that changes all the named ranges to a single cell that is my email address. Using this, I can enter a sort of 'testing mode' so that I can test scripts easily without sending out emails mistakenly. – RossV Jan 06 '15 at 00:17
  • So, when I switch between 'testing mode' and 'live' I change the Named Ranges using A1 notation hardcoded into the script. I would like the be able to have these ranges assigned to Named Ranges no matter the length, without having to go in and change the script all the time. – RossV Jan 06 '15 at 00:19
  • What I use for testing mode is parsing an arg, so when there's an argument it's live mode, if not, I'm testing. Example: function sendMail( live ){ if( live ){var emailsRange = ss.getRange(2, 1, -1)}else{ var emailsRange = ss.getRange(2, 2, -1)};. This way, when debugging, the live will be null and emailsRange will be the testing range, if there's an arg, it will be the real emails. – Kriggs Jan 06 '15 at 00:38
  • That's a neat idea, thanks! I'll see if using this method solves my issue. – RossV Jan 06 '15 at 13:22

0 Answers0