简体   繁体   中英

Google sheet moving cells

i have google sheet with 9108 rows that follow certain order , but i strugling with moving 2nd row next to first and 3rd next to other ( picture down below ), i cant just take all 9thousand rows and just split it to 3 thousand columns, i trying to find script solution like this :

move every other row next to row before
move every row after moved row next "other" row
remove blank rows

and do it with all rows in sheet without destroying order

图片与例子

thanks anybody for helping or finding solution.

edit:

This works how i need, but it creates columns and with 9108 rows it stops after 100 rows because there are too many cells.

function Test() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet()
  var ss = spreadsheet.getActiveSheet()

  var index = 1
  var rowSpan = 1
  var columnSpan = 1

  while (index <= ss.getLastRow()) {
    ss.getRange(index, 1, 1, index + 1).moveTo(ss.getRange(rowSpan, columnSpan))
    columnSpan = columnSpan + 3

    if (columnSpan == 13) {
      columnSpan = 1
      rowSpan++
    }

    index++
  }
}

Please try with this function:

 function Test() { var spreadsheet = SpreadsheetApp.getActiveSpreadsheet() var ss = spreadsheet.getActiveSheet() var index = 1 var rowSpan = 1 var columnSpan = 1 var value while (index <= ss.getLastRow()) { value = ss.getRange(index, 1).getValue() ss.getRange(rowSpan, columnSpan).setValue(value) columnSpan++ if (columnSpan == 4) { columnSpan = 1 rowSpan++ } index++ } } 

You can register a new macro and then copy/paste the content of this function inside of it.

After that, you can clear extra data you don't need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM