LoginSignup
0
0

More than 3 years have passed since last update.

GASでunpivotっぽいことをやる

Posted at

以下の図のような変更をしたい

Before

before.PNG

Afte

after.PNG

function myFunction() {
  var sheet = SpreadsheetApp.getActiveSheet(); 
    for(var i = 1; i <= 5000; i++) { //最大の行数+α 行がどんどん追加されていくため
    for(var j = 3; j>=2; j--){ //最大の列数 2は固定 1列目はそのまま入れるため
      a = sheet.getRange(i, j)
      if(!a.isBlank()){
       sheet.insertRowAfter(i);
       sheet.getRange(i+1, 1).setValue(a.getValue());
       a.clear() // 移動したら消す
       Logger.log(a.getValue());
      }
    }
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0