在 Google Scripts 中将值从一列复制到另一列

高铁

我有一个数据表,它从谷歌表中的一系列 VLOOKUP 中提取其信息。我一直在编辑改变我的数据表的源。我需要一个谷歌脚本代码,它将受公式影响的单元格复制到另一列不会受到影响的列。我尝试立即复制所有内容以移动,但第二次激活时,现在空白的单元格覆盖了以前我能够使用 VBA 成功完成此任务,但我无法弄清楚转换。这是我到目前为止所拥有的:

function CopyCells() {

var sheet2 = SpreadsheetApp.getActive().getSheetByName('Records');
var loc = sheet2.getRange("C2:C126").getValues();
var taget_sheet = sheet2.getRange("D2:D126");
for(i = 1;i == "Present";i++){ i.copyTo("target_sheet")}       
}

我的 VBA 代码:

 Dim ColERange As Range
 Dim ColFRange As Range 
 Set ColERange = Range("E1:E100") 
 Set ColFRange = Range("F1:F100") 
 Dim Cell As Range 
 For Each Cell In ColERange 
   If Cell.Value = "Present" 
     Then Cell.Offset(0, 1).Value = Cell.Value 
   ElseIf Cell.Value = "Absent" 
     Then Cell.Offset(0, 1).Value = Cell.Value 
   ElseIf Cell.Value = "" 
     Then Cell.Offset(0, 1).Value = Cell.Value 
   End If 
 Next Cell   
超人

试试这个:

/*
 Dim ColERange As Range
 Dim ColFRange As Range 
 Set ColERange = Range("E1:E100") 
 Set ColFRange = Range("F1:F100") 
 Dim Cell As Range 
 For Each Cell In ColERange 
   If Cell.Value = "Present" 
     Then Cell.Offset(0, 1).Value = Cell.Value 
   ElseIf Cell.Value = "Absent" 
     Then Cell.Offset(0, 1).Value = Cell.Value 
   ElseIf Cell.Value = "" 
     Then Cell.Offset(0, 1).Value = Cell.Value 
   End If 
 Next Cell   
*/    

我认为这个版本是你想要的,因为只要改变一件事,你就可以改变你复制到的列..

function CopyCells1(col) {
  var col=col || 1;
  var sh=SpreadsheetApp.getActive().getSheetByName('Records');
  var rg1=sh.getRange("C2:C126");
  var vA=rg1.getValues();
  var rg2=rg1.offset(0, col);//Changing the column offset allows you to gain access to the other columns. Note: it can be negative.
  var vB=rg2.getValues();
  for(var i=0;i<vA.length;i++){
    if((vA[i][0]=='Present')||(vA[i][0]=='Absent')){
      vA[i][0]=vB[i][0];
    }
  }
  rg2.setValues(vB);
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将值复制到 Google Scripts 中的另一列

使用Node.js Google Sheets API将背景色从一列复制到另一列

使用Apps脚本将非连续单元格从Google表格中的一列复制到另一列

如何在熊猫中将特定值从一列复制到另一列

将条件值从一列复制到另一列

将时间戳值从一列复制到另一列失败

将满足条件的单个值从一列复制到另一列

使用Pandas将值从一列复制到另一列

如何将值从一列复制到另一列?

当新列值为空时,将值从一列复制到另一列

将值从一列复制到同一表中的另一列

检查上一行的值以将数据从一列复制到另一列

将值从一列复制到另一条sql

有条件地将值从一列复制到另一列

如果满足条件,pandas将值从一列复制到另一列

根据条件(使用熊猫)将值从一列复制到另一列

将数据从一列复制到另一列

SQL将数据从一列复制到另一列

将数据从一列复制到另一列

将因子级别顺序从一列复制到另一列

在一列中查找值,如果匹配,则添加另一列中的值Google Script Google表格

希望根据另一列的值在 Google 表格中将复选框值设置为 TRUE

Google表格:如何使用公式从满足条件的列中提取所有值到Googlesheet中的另一列?

将值从一个数据框列复制到另一列

根据另一变量将值从一列复制到其他多个列

Power Shell将一列的值复制到另一列表中的一列

使用Google查询作为数组公式,根据另一列中的信息对一列中的值求和

在 Google 表格中将特定列合并为一列

将一列从一个DataFrame复制到另一个提供NaN值?