[英]Scroll a row to the top of the screen based on cell value: Google Sheet Script
I have a google spreadsheet.我有一个谷歌电子表格。 Column M are numbers (number of days left), ranging from -33 to 35. I'm a newbie to script, and really have no idea how to implement the following: M 列是数字(剩余天数),范围从 -33 到 35。我是脚本新手,真的不知道如何实现以下内容:
a) When opening the spreadsheet, the row which Column M has a value of 1, will scroll up automatically to the very top of the screen. a) 打开电子表格时,M 列值为 1 的行将自动向上滚动到屏幕的最顶部。
b) When several rows are having a value of 1 in the M column, all rows with 1 will scroll to the top altogether, starting with the row with the first 1, followed by the rest of ones. b) 当 M 列中有几行的值为 1 时,所有带 1 的行将一起滚动到顶部,从第一个 1 的行开始,然后是一个的 rest。
I hope you can help me.我希望你能帮助我。 Thanks.谢谢。
The function goes to sh.getRange(sh.getMaxRows())
and I activate() it there and the I jump back to the sh.getRange(1,13,sh.getLastRow(),1).getValues().flat().indexOf(1) ) + 1
which is the row number of the number 1 in column M or 13. function 转到sh.getRange(sh.getMaxRows())
并在那里激活它,然后我跳回到sh.getRange(1,13,sh.getLastRow(),1).getValues().flat().indexOf(1) ) + 1
是第 M 列或第 13 列中数字 1 的行号。
function scrollToOne() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getActiveSheet();
sh.getRange(sh.getMaxRows(),1).activate();
SpreadsheetApp.flush();
const row = sh.getRange(1,13,sh.getLastRow(),1).getValues().flat().indexOf(1) + 1;
sh.getRange(row,1).activate();
SpreadsheetApp.flush();
}
My active sheet:我的活动表:
COL1 COL1 | COL2 COL2 | COL3 COL3 | COL4 COL4 | COL5 COL5 | COL6 COL6 | COL7 COL7 | COL8 COL8 | COL9 COL9 | COL10 COL10 | COL11 COL11 | COL12 COL12 | COL13 COL13 | COL14 COL14 | COL15 COL15 | COL16 COL16 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 1 | 2 2 | 3 3 | 4 4 | 5 5 | 6 6 | 7 7 | 8 8 | 9 9 | 10 10 | 11 11 | 12 12 | -10 -10 | 14 14 | 15 15 | 16 16 |
2 2 | 3 3 | 4 4 | 5 5 | 6 6 | 7 7 | 8 8 | 9 9 | 10 10 | 11 11 | 12 12 | 13 13 | -9 -9 | 15 15 | 16 16 | 17 17 |
3 3 | 4 4 | 5 5 | 6 6 | 7 7 | 8 8 | 9 9 | 10 10 | 11 11 | 12 12 | 13 13 | 14 14 | -8 -8 | 16 16 | 17 17 | 18 18 |
4 4 | 5 5 | 6 6 | 7 7 | 8 8 | 9 9 | 10 10 | 11 11 | 12 12 | 13 13 | 14 14 | 15 15 | -7 -7 | 17 17 | 18 18 | 19 19 |
5 5 | 6 6 | 7 7 | 8 8 | 9 9 | 10 10 | 11 11 | 12 12 | 13 13 | 14 14 | 15 15 | 16 16 | -6 -6 | 18 18 | 19 19 | 20 20 |
6 6 | 7 7 | 8 8 | 9 9 | 10 10 | 11 11 | 12 12 | 13 13 | 14 14 | 15 15 | 16 16 | 17 17 | -5 -5 | 19 19 | 20 20 | 21 21 |
7 7 | 8 8 | 9 9 | 10 10 | 11 11 | 12 12 | 13 13 | 14 14 | 15 15 | 16 16 | 17 17 | 18 18 | -4 -4 | 20 20 | 21 21 | 22 22 |
8 8 | 9 9 | 10 10 | 11 11 | 12 12 | 13 13 | 14 14 | 15 15 | 16 16 | 17 17 | 18 18 | 19 19 | -3 -3 | 21 21 | 22 22 | 23 23 |
9 9 | 10 10 | 11 11 | 12 12 | 13 13 | 14 14 | 15 15 | 16 16 | 17 17 | 18 18 | 19 19 | 20 20 | -2 -2 | 22 22 | 23 23 | 24 24 |
10 10 | 11 11 | 12 12 | 13 13 | 14 14 | 15 15 | 16 16 | 17 17 | 18 18 | 19 19 | 20 20 | 21 21 | -1 -1 | 23 23 | 24 24 | 25 25 |
11 11 | 12 12 | 13 13 | 14 14 | 15 15 | 16 16 | 17 17 | 18 18 | 19 19 | 20 20 | 21 21 | 22 22 | 0 0 | 24 24 | 25 25 | 26 26 |
12 12 | 13 13 | 14 14 | 15 15 | 16 16 | 17 17 | 18 18 | 19 19 | 20 20 | 21 21 | 22 22 | 23 23 | 1 1 | 25 25 | 26 26 | 27 27 |
13 13 | 14 14 | 15 15 | 16 16 | 17 17 | 18 18 | 19 19 | 20 20 | 21 21 | 22 22 | 23 23 | 24 24 | 2 2 | 26 26 | 27 27 | 28 28 |
14 14 | 15 15 | 16 16 | 17 17 | 18 18 | 19 19 | 20 20 | 21 21 | 22 22 | 23 23 | 24 24 | 25 25 | 3 3 | 27 27 | 28 28 | 29 29 |
15 15 | 16 16 | 17 17 | 18 18 | 19 19 | 20 20 | 21 21 | 22 22 | 23 23 | 24 24 | 25 25 | 26 26 | 4 4 | 28 28 | 29 29 | 30 30 |
5 5 | |||||||||||||||
6 6 | |||||||||||||||
7 7 | |||||||||||||||
8 8 | |||||||||||||||
9 9 | |||||||||||||||
10 10 | |||||||||||||||
11 11 | |||||||||||||||
12 12 | |||||||||||||||
13 13 | |||||||||||||||
14 14 | |||||||||||||||
15 15 | |||||||||||||||
16 16 | |||||||||||||||
17 17 | |||||||||||||||
18 18 | |||||||||||||||
19 19 | |||||||||||||||
20 20 | |||||||||||||||
21 21 | |||||||||||||||
22 22 | |||||||||||||||
23 23 | |||||||||||||||
24 24 | |||||||||||||||
25 25 | |||||||||||||||
26 26 | |||||||||||||||
27 27 | |||||||||||||||
28 28 | |||||||||||||||
29 29 | |||||||||||||||
30 30 | |||||||||||||||
31 31 | |||||||||||||||
32 32 | |||||||||||||||
33 33 | |||||||||||||||
34 34 | |||||||||||||||
35 35 | |||||||||||||||
36 36 | |||||||||||||||
37 37 | |||||||||||||||
38 38 |
Sheet after running the function:运行 function 后的工作表:
12 12 | 13 13 | 14 14 | 15 15 | 16 16 | 17 17 | 18 18 | 19 19 | 20 20 | 21 21 | 22 22 | 23 23 | 1 1 | 25 25 | 26 26 | 27 27 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
13 13 | 14 14 | 15 15 | 16 16 | 17 17 | 18 18 | 19 19 | 20 20 | 21 21 | 22 22 | 23 23 | 24 24 | 2 2 | 26 26 | 27 27 | 28 28 |
14 14 | 15 15 | 16 16 | 17 17 | 18 18 | 19 19 | 20 20 | 21 21 | 22 22 | 23 23 | 24 24 | 25 25 | 3 3 | 27 27 | 28 28 | 29 29 |
15 15 | 16 16 | 17 17 | 18 18 | 19 19 | 20 20 | 21 21 | 22 22 | 23 23 | 24 24 | 25 25 | 26 26 | 4 4 | 28 28 | 29 29 | 30 30 |
5 5 | |||||||||||||||
6 6 | |||||||||||||||
7 7 | |||||||||||||||
8 8 | |||||||||||||||
9 9 | |||||||||||||||
10 10 |
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.