I have a simple spreadsheet table with 20 columns, with an application that update rows on the first 14 columns. When one row is modified I am trying to capture the row using getActiveRange(). But I am getting 12 columns instead of the expected 14. No error. Just less columns than expected.
var ssPlat= SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Plateau");
var aValues= ssPlat.getActiveRange().getValues();
var aCol = ssPlat.getActiveRange().getLastColumn()
Logger.log("Columns:"+aCol+":"+aValues)
I don't want to hard code the range because more columns may be added later.
Please help.
Related
how to pull column from different sheet..
I've a sheet using the below formula to get the column(n rows) from Sheet1 to Sheet2 however I'm getting zeros after nth row. How to avoid zeros here ??
=IF(NOT(ISBLANK(Sheet1!C1)),Sheet1!C:C,"")
I'm doing the same for A,B,C columns to get data from Sheet1 to Sheet2. Any better formula ?
zeros are coming because the original column doesn't have data after nth row. for example if zero occur at 301 for column c means data in the column C has values upto 300 rows.
we can avoid this issue in two ways
stop copying formula after you get zeros
or
Put a unique word in the formula (here stopcopying)
=IF(LEN(IF(NOT(ISBLANK(Sheet1!C12)),Sheet1!C:C,""))=0,"stopcopying",IF(NOT(ISBLANK(Sheet1!C1)),Sheet1!C:C,""))
Find "Stopcopying" keyword and replace without giving any word ( ctrl F and R)
This is the only way I can see and this answered my question:
=FILTER($B:$E,(B:B<>""))
What is the syntax for selecting the full range of rows which contain data?
Say for instance I have 200 rows of data. Im running some functions which loop through rows. If I wanted to select the range of these rows manually from column A, I would write is as A1:A200.
But is there a way to write it from "A1" : "last row in the column A that contains an entry"
Alternatively is there a way to write A1:"end of column A, regardless of entries"?
thanks
You can write A1:A to get the entire column, or A1:Z to get a range of columns. In Apps Script, you can call sheet.getLastRow() (or sheet.getLastColumn()) to get the last row containing data and use that to write your loops.
References
sheet.getLastRow()
sheet.getLastColumn()
You can also consider the use of getDataRange().This method returns a Range corresponding to the dimensions in which data is present.
I am new to google script. I have a scenario like the below.
I have Sheet1 with Column A and B. Usually I try to store decimal values in to it. I mean integer part in column-A and decimal part in Column-B
For example:
Scenario-1:
It the value is 23.75 then Column-A should be 23 and ColumnB would be 75
Scenario-2:
If the value is 22.00 then Column-A should be 22 and ColumnB would be 00
I tried like this
sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
column = sheet.getRange("B:B");
column.setNumberFormat("#");
sRange = "O1:O" + 65;
cell = sheet.getRange(sRange);
cell.setValue("00");
This works fine for scenario-1, but for scenario-2 it displays only one zero (leading zero is automatically removed). I tried to change the complete column formatting to plain text but no luck.
I am strugging to achieve this for the past two days. Any help is greatly appreciated.
Adding an apostrophe:
cell.setValue("'00");
might be considered adequate.
I've got a list of dates, clients, and shift data in a spreadsheet (rows A5:D34). I want to write this data to the last row of the sheet. Unfortunately, the number of rows is variable. On one week, the data may be 17 rows; later, it may be 23 rows.
I want to "archive" the data by moving the used rows to the bottom of the sheet.
I'm looking for a code (google script) solution that can work with the fact that the range to be copied is always 4 columns wide, but a variable number of rows.
Thanks for all your help!
This is a quite common problem where we might not know or have to manually include the total number of rows in the sheet. We can use, getRange() with last row values or getDataRange() to extract the range.
getRange(start_row,start_column,number_of_rows,number_of_columns);
to use the last row in the above syntax starting from A1, simply change the parameters as below.
var range = getRange(1,1,sheet.getLastRow(),sheet.getLastColumn());
The second option is to use getDataRange() which is
var range = sheet.getDataRange();
PS : Mind that range is a 2D array.
Hope this helps :)
I would suggest using sheet.getDataRange() to know how many rows and columns contain data. Once you know this you can derive the bottom row.
To quickly go through the returned values, I would suggest using sheet.getDataRange().getValues() which will return a 2 dimensional array with all the values stored in your sheet.
To know the last row containing data you can then easily do the following:
var lastRow = sheet.getDataRange.getValues().length;
Note that since the length of an array starts counting at 0 for the first row whereas when you want to set values back to your sheet your row count will start at 1. This means you need to add 1 to the lastRow count.
Now that you know the last row you can do some cleanup first to remove a previous bottom row with sheet.deleteRow(lastRow+1);
To then add a new bottom row you can simply use the append function where you pass an array with all the values for all cells of the row like this:
sheet.appendRow(["cellInColumnA";"cellInColumnB","cellInColumnC"]);
I have imported a huge excel file into matlab. The file is a database with 5 columns and 175000 rows. I want the maximum value of every 24 rows of the third column.
can anyone help me plz?
I hope I got what you want right,
I believe you can do something like this:
(forgive me I'm not writing matlab coding)
col = 3
for i = 1 to number_of_rows
Add the element at (i, col) to a new array
i=i+23
end for
then fine the maximum value in the new array you created in the loop, hope this helps