只适用于一系列单元格的宏。

huangapple go评论56阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月18日 05:44:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76276399.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定