将列 A3:A9-E3:A9: 复制到另一个 sheet 中的 A、C、E、G、I

Copy column A3:A9-E3:A9: to A,C,E,G, I in an other sheet

是否可以从列 A3:A9-E3:A9: 复制,然后在另一个 sheet 中将它们定位到 A、C、E、G、I?

Example

使用这个公式:

=ARRAYFORMULA(SPLIT(TRANSPOSE(QUERY(TRANSPOSE("♦"&A3:E9&"♦");;999^99)); "♦"))

然后复制 CTRL+C 和 re-paste/paste 结束于 CTRL+SHIFT+V

如果您希望能够使用中间的列,我认为您最好的选择是使用 Google Apps Script. I don't think it is possible to do this with a sheets built-in function or even with an Apps Script custom function

首先,通过选择Tools > Script editor打开一个绑定脚本,并将以下函数复制到脚本中:

function copyRange() {
  // Retrieve original range:
  var inputRange = "'Ark1'!A3:E9"; // Range of original columns (please change this according to your preferences)
  var inputValues = SpreadsheetApp.getActive().getRange(inputRange).getValues();
  // Transpose array so that outer array corresponds to columns:
  var transposedValues = inputValues[0].map(function(column, i) {
    return inputValues.map(function(row) {
      return row[i];
    });
  });
  // Get selected range (this will be the destination range):
  var outputRange = SpreadsheetApp.getActiveRange();
  var targetSheet = outputRange.getSheet();
  var row = outputRange.getRow();
  var col = outputRange.getColumn();
  // Copy the source range to the destination (ignoring each second column):
  transposedValues.forEach(function(column, j) {
    for (var i = 0; i < column.length; i++) {
      targetSheet.getRange(row + i, col + j * 2).setValue(column[i]);
    };
  });
}'

此脚本执行以下操作:

  • 通过getRange and getValues.
  • 检索特定范围内的值,在此示例的第一行中定义
  • "Transposes"检索到的二维数组对应source range的值,这样外层数组的每个元素对应一列,这样写的过程会更简单,如[=15中所述=].
  • 通过getActiveRange
  • 检索当前选择的范围
  • setValues.
  • 将源范围复制到当前选择的范围

当然,这种方法的问题在于 运行 这种函数比内置或自定义函数更不舒服。您可以附加此功能 to an image or to a menu 以减轻工作流程的痛苦。但是我想不出更好的解决方案。

至关重要的是,您必须更改输入范围的参考(在此示例中 'Ark1'!A3:E9)。

参考:

希望对您有所帮助。