在Google表格中移动单元格范围 [英] Shift Cell Range in Google Sheets
问题描述
我正在尝试获取一系列单元格,并将它们全部向右移动一个单元格.我希望这种情况每周自动发生一次.我知道在脚本编辑器中,我可以为其创建一个触发器以安排每周计划,但不确定如何编写代码.
I'm trying to take a range of cells and shift them all to the right by one cell. I'd like this to occur once per weekly automatically. I'm aware in the Script editor I can create a trigger for it to schedule weekly, but I'm not sure how to code it.
如果有人可以帮助提供一个代码,使我能够指示哪个SHEET和CELL RANGE向右移动一个单元格,我将不胜感激.
If someone can help provide a code that allows me to indicate which SHEET and CELL RANGE to shift to the right by one cell, I would appreciate it.
基本上,我要完成的工作是跟踪数周的数据.每周都会更新工作表,我希望较早的数据向右移动,基本上表明该数据已经过一周了.
Basically, what I'm trying to accomplish is tracking data for a number of weeks. Each week the sheet will be updated, and I would like the older data to shift right one, basically indicating that the data has gotten a week older.
此外,我只尝试将数据保留6周左右,因此数据不会永远持续下去.
In addition, I'm only trying to keep data for like 6 weeks, so the data isn't ongoing forever.
举例说明:列A =当前星期(手动更新). B-F列=前几周(1-5周前).
A bit of an example: Column A = current week (updated manually). Columns B-F = previous weeks (1-5 weeks ago).
每周一次,应将A-E列中的数据右移1以保留数据.轮班后,将在A列中手动更新数据以表示当前星期.然后,这将导致显示当前一周的数据以及另外5周的数据……总计6周的数据.
Once a week, the data in columns A-E should be shifted right 1 to preserve the data. After the shift, data is manually updated in Column A to represent the current week. This would then result in showing data for the current week and 5 additional weeks... totaling 6 weeks of data.
我想知道是否有一种方法可以移动列,同时排除标题行,如果可能的话,而不是范围.
I'd be interested if there is a way to just shift columns while excluding the header row, instead of a range, if possible.
推荐答案
可以尝试这样的事情吗?
Could try something like this?
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// This inserts 1 columns before the first column
sheet.insertColumnsBefore(1, 1);
// labels the weeks static
ss.getRange('A1').setFontWeight("bold").setValue("Week1").setBackground("#BBBBBB");
ss.getRange('B1').setFontWeight("bold").setValue("Week2").setBackground("#BBBBBB");
ss.getRange('C1').setFontWeight("bold").setValue("Week3").setBackground("#BBBBBB");
ss.getRange('D1').setFontWeight("bold").setValue("Week4").setBackground("#BBBBBB");
ss.getRange('E1').setFontWeight("bold").setValue("Week5").setBackground("#BBBBBB");
ss.getRange('F1').setFontWeight("bold").setValue("Week6").setBackground("#BBBBBB");
}
这篇关于在Google表格中移动单元格范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!