在Google表中,我想创建一个宏,该宏将在手动填充该行中的另一行时自动填充每一行的列。自动填充的单元格将使用一个公式,该公式采用了一部分信息(日期),该信息已手动输入并使用公式将其与随机数相连,以创建唯一的ID。插入和执行公式后,宏需要复制然后粘贴“值”该公式的结果。关键是要根据触发事件自动创建稳定的ID(行的日期输入)。
在伪代码中,这是我希望宏执行的过程:
when (date in yyyy-mm-dd format entered into A[i]) {
fill B[i] with =CONCATENATE(SUBSTITUTE(LEFT(A[i], 7), "-", ""),RANDBETWEEN(0,1000000000));
copy B[i];
PASTE_VALUES B[i] in B[i];
}
如果我忽略了以前的答案来解决此问题,则表示歉意。我不是编码的新手,但是我是Google表中编码的新手,不确定要用来描述我所追求的条款或短语。
In Google Sheets, I want to create a macro that will automatically populate a column in each row when another column in that row is manually filled. The autofilled cell will use a formula that takes a chunk of the information (date) that's been entered manually and use a formula to concatenate it with a random number in order to create a unique ID. After inserting and executing the formula, the macro needs to copy and then paste "values only" the result of that formula. The point is to automatically create a stable ID in response to a triggering event (entry of date in row).
In pseudocode, here's the process I'd like the macro to execute:
when (date in yyyy-mm-dd format entered into A[i]) {
fill B[i] with =CONCATENATE(SUBSTITUTE(LEFT(A[i], 7), "-", ""),RANDBETWEEN(0,1000000000));
copy B[i];
PASTE_VALUES B[i] in B[i];
}
Apologies if I've overlooked a previous answer that solves this problem. I'm not new to coding, but I am new to coding in Google Sheets and am not sure what terms or phrases to use to describe what I'm after.
发布评论
评论(2)
我相信您的目标如下。
yyyy-mm-dd格式的值放在单元格“ a1”中时,您想将
= concatenate的公式放置7),“ - ”,“”),randbetbetewewnek(0,1000000000))
到“ b1”。在这种情况下,以下示例脚本怎么样?
示例脚本:
请将以下脚本复制到电子表格的脚本编辑器,然后保存脚本。而且,请设置要使用的表名称。当您使用此脚本时,请将带有
yyyy-mm-dd的格式的值放在“ A”列中,因此,该脚本已运行。
参考:
I believe your goal is as follows.
yyyy-mm-dd
is put to the cell "A1", you want to put the formula of=CONCATENATE(SUBSTITUTE(LEFT(A1, 7), "-", ""),RANDBETWEEN(0,1000000000))
to the cell "B1".In this case, how about the following sample script?
Sample script:
Please copy and paste the following script to the script editor of Spreadsheet, and save the script. And, please set the sheet name you want to use. When you use this script, please put the value with the format of
yyyy-mm-dd
to the column "A", by this, the script is run.Reference:
这是我想到的脚本:
包括评论以解释正在发生的一切。下面的链接是我用来测试的电子表格。它设置为允许编辑,因此请随时使用它自己测试脚本。
希望这会有所帮助!
This is the script I came up with:
Comments are included to explain everything that is happening. Linked below is the spreadsheet I used to test this. It is set to allow editing, so feel free to use it to test the script yourself.
https://docs.google.com/spreadsheets/d/1UONgRPBEbxn8CQeiRSPS4eFKHjh4ae8hXGYn6ImHxeI/edit?usp=sharing
Hope this helps!