我正在尝试做一个非常基本的副本粘贴宏,其中:
- 将单元格中的值
- 通过公式更改为公式,单元i20更新中的值
- 复制单元i20中的值粘贴到j20到j20
,然后再次完成周期:
- 更改值单元格H20(第一次有不同的值
在周围)
- 通过公式,单元i20中的值复制了
- 单元i20中的值粘贴到J21
,然后再次将其粘贴到J22中。
我发现的是,一旦宏运行,小区j20,j21和j22中的值是相同的,何时应不同,因为在过程中i20中的值会更改。
这几乎就像它在最后一次粘贴了i20中的值,而不是整个三个单元格。
有人知道为什么这是什么以及我如何解决?我通过录制而不是编码来制作这个宏。
var evendersheet = dreversheetapp.getactive();
电子表格。getRange('h20')。activate();
电子表格。getCurrentCell()。setValue('2');
电子表格。getRange('j20')。activate();
evredsheet.getRange('i20')。copyto(everdsheet.getActiverange(),vredsheetapp.copypastepe.paste_values,false);
电子表格。getRange('h20')。activate();
vendersheet.getCurrentCell()。setValue('3');
电子表格。getRange('j21')。activate();
evredsheet.getRange('i20')。copyto(everdsheet.getActiverange(),vredsheetapp.copypastepe.paste_values,false);
电子表格。getRange('h20')。activate();
vendersheet.getCurrentCell()。setValue('4');
电子表格('j22')。activate();
evredsheet.getRange('i20')。copyto(everdsheet.getActiverange(),vredsheetapp.copypastepe.paste_values,false);
I am trying to do a very basic copy paste macro where it:
- Changes the value in cell H20
- Through a formula, the value in cell I20 updates
- Copy Pastes the value in cell I20 to J20
It then completes the cycle again:
- Changes the value in cell H20 (a different value to the first time
around)
- Through a formula, the value in cell I20 updates
- Copy Pastes the value in cell I20 to J21
And once again into J22.
What I am finding is that once the macro has run, the value in cell J20, J21 and J22 is the same, when they should be different, since the value in I20 changes during the process.
It's almost like it's pasting the value in I20 at once to all three cells at the end, rather than throughout.
Does anyone know why this is and how I can fix it? I made this macro by recording it, not coding.
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('H20').activate();
spreadsheet.getCurrentCell().setValue('2');
spreadsheet.getRange('J20').activate();
spreadsheet.getRange('I20').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
spreadsheet.getRange('H20').activate();
spreadsheet.getCurrentCell().setValue('3');
spreadsheet.getRange('J21').activate();
spreadsheet.getRange('I20').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
spreadsheet.getRange('H20').activate();
spreadsheet.getCurrentCell().setValue('4');
spreadsheet.getRange('J22').activate();
spreadsheet.getRange('I20').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
发布评论
评论(1)
您需要在每个变化之间刷新表格
应用所有等待的电子表格更改。
说明
ELI5类比如何:
据我所知,当您运行脚本时,Google拍摄了表格并根据其运行。因为您有一个基于输入的价值的公式,并且由于您采取结果,因此必须告诉Google:刷新工作表并拍摄新图像。
You need to refresh your sheet between each changes of value
flush() Applies all pending Spreadsheet changes.
explanation
How about an ELI5 analogy:
as far as i know, when you run the script, google takes an image of the sheet and runs based on it. Because you have a formula based on the value you entered, and because you take the result, you have to tell google: refresh the sheet and take a new image.