英文:
I need the macro to apply only to a range of cells
问题
需要宏以var targetRange =targetSheet.getRange(targetSheet.getLastRow()+1,1)为参考,但仅从1到7的单元格范围内获取数据,因为我需要在宏提取的数据前面写入内容。当使用getLastRow()+1时,它会复制表格中的所有内容,包括我写入的信息。
我喜欢应用脚本,但我需要更多帮助。
英文:
I need the macro to take as reference var targetRange =targetSheet.getRange(targetSheet.getLastRow()+1,1); but only from a range of cells, from 1 to 7.
because I need to write in front of the data that the macro brings to me
when using getLastRow()+1 it takes everything I write in the sheet and continues copying the same information.
i like app script but i need more assistance
答案1
得分: 1
Sure, here are the translated parts:
A | B | C | D | E | F | G | H | I | J | |
---|---|---|---|---|---|---|---|---|---|---|
1 | COL1 | COL2 | COL3 | COL4 | COL5 | COL6 | COL7 | COL8 | COL9 | COL10 |
2 | 1 | 8 | 1 | 1 | 5 | 2 | 3 | 0 | 0 | 1 |
3 | 10 | 9 | 8 | 2 | 3 | 6 | 5 | 7 | 3 | 6 |
4 | 9 | 8 | 8 | 2 | 8 | 1 | 4 | 4 | 9 | 8 |
function getvaluesfromARangeofCells() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet1");
const [[a1,,,,,,,,,],[,b2,,,,,,,,],[,,c3,,,,,,],[,,,d4,,,,,]] = sh.getDataRange().getValues();
Logger.log("a1: %s, b2:%s, c3:%s, d4: %s",a1,b2,c3,d4);
}
Execution log
5:06:07 PM Notice Execution started
5:05:58 PM Info a1: COL1, b2:8.0, c3:8.0, d4: 2.0
5:06:10 PM Notice Execution completed
英文:
A | B | C | D | E | F | G | H | I | J | |
---|---|---|---|---|---|---|---|---|---|---|
1 | COL1 | COL2 | COL3 | COL4 | COL5 | COL6 | COL7 | COL8 | COL9 | COL10 |
2 | 1 | 8 | 1 | 1 | 5 | 2 | 3 | 0 | 0 | 1 |
3 | 10 | 9 | 8 | 2 | 3 | 6 | 5 | 7 | 3 | 6 |
4 | 9 | 8 | 8 | 2 | 8 | 1 | 4 | 4 | 9 | 8 |
function getvaluesfromARangeofCells() {
const ss = SpreadsheetApp.getActive();
const sh = ss.getSheetByName("Sheet1");
const [[a1,,,,,,,,,],[,b2,,,,,,,,],[,,c3,,,,,,],[,,,d4,,,,,]] = sh.getDataRange().getValues();
Logger.log("a1: %s, b2:%s, c3:%s, d4: %s",a1,b2,c3,d4);
}
xecution log
5:06:07 PM Notice Execution started
5:05:58 PM Info a1: COL1, b2:8.0, c3:8.0, d4: 2.0
5:06:10 PM Notice Execution completed
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论