1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Excel 2列のデータを1列にして、値を交互に並べ替えたいとき

Last updated at Posted at 2019-11-19

やりたいこと

下記みたいなデータがあるとする

No A列 B列
1 1 5
2 2 6
3 3 7
4 4 8

こうしたい

No C列
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8

解決方法

下記をC列にペーストして下にスライド。

=IF(MOD(ROW(),2)=1,INDIRECT("A"&INT(ROW()/2)+1),INDIRECT("B"&(ROW()/2)))

解説

まず単純にIF分岐。MOD(ROW(),2)が1だったらINDIRECT("A"&INT(ROW()/2)+1)実行。
MODは剰余を求めます。ROWは行番号を取得します。
上記を簡単に以下のように表にしてみると、奇数行は1,偶数行は0になります。

No =ROW() =MOD(ROW(),2)
1 1 1
2 2 0
3 3 1
4 4 0

で、次にINDIRECTで指定しているセル名を求めている部分も表にすればわかりやすいです。

No =ROW() =MOD(ROW(),2) IF条件YESの場合(INT(ROW()/2)+1) IF条件NOの場合=(ROW()/2)
1 1 1 1 0
2 2 0 2 1
3 3 1 2 1
4 4 0 3 2
5 5 1 3 2
6 6 0 4 3

上記により、奇数行の場合はA1セルを参照、偶数行の場合はB1セルを参照、A2B2を参照するとなるわけですね。。
(赤文字部分をINDIRECTで参照している)

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?