-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConnectedSheetValue.js
More file actions
37 lines (31 loc) · 920 Bytes
/
ConnectedSheetValue.js
File metadata and controls
37 lines (31 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
Created by: RemcoE33
https://github.com/RemcoE33/apps-script-codebase
*/
/**
* Returns the values from an sheet range left or right from the current sheet.
*
* @param {"A2:B5"} range Enter a cell as a string: "A1".
* @param {"right"} direction Choose left/right: "right".
* @return value from linked sheet.
* @customfunction
*/
function CONNECTED_SHEET_VALUE(range,direction){
const ss = SpreadsheetApp.getActiveSpreadsheet()
const currentIndex = ss.getActiveSheet().getIndex();
const sheets = ss.getSheets();
let index = 0;
if (direction.toLowerCase() == 'right'){
index = 1
} else if (direction.toLowerCase() == 'left'){
index = -1
}
const sheetIndex = currentIndex + index;
if (index == 0){
return 'Wrong direction'
} else if (sheetIndex > sheets.length){
return 'No sheet in direction'
} else {
return sheets[sheetIndex - 1].getRange(range).getValues();
}
}