- ベストアンサー
エクセルのデータ整理におけるマクロの活用法
- エクセルのデータ整理を行う際に、マクロを活用する方法をご紹介します。
- sheet1にあるデータの合計をsheet2の任意のセルに書き込むために、特定のセル範囲のデータを移動させる処理を行います。
- 素人でも理解しやすい手順とポイントを解説しています。
- みんなの回答 (4)
- 専門家の回答
質問者が選んだベストアンサー
Sheet2のA1に =SUM(OFFSET(Sheet1!A$1,(ROW()-1)*4,0,4,1)) と入力して、下にドラッグ。
その他の回答 (3)
- DIooggooID
- ベストアンサー率27% (1730/6405)
以下を Sheet2 A列に貼り付けてください。 =SUM(Sheet1!A1:A4) =SUM(Sheet1!A5:A8) =SUM(Sheet1!A9:A12) =SUM(Sheet1!A13:A16) =SUM(Sheet1!A17:A20) =SUM(Sheet1!A21:A24) =SUM(Sheet1!A25:A28) =SUM(Sheet1!A29:A32) =SUM(Sheet1!A33:A36) =SUM(Sheet1!A37:A40) =SUM(Sheet1!A41:A44) =SUM(Sheet1!A45:A48) =SUM(Sheet1!A49:A52) =SUM(Sheet1!A53:A56) =SUM(Sheet1!A57:A60) =SUM(Sheet1!A61:A64) =SUM(Sheet1!A65:A68) =SUM(Sheet1!A69:A72) =SUM(Sheet1!A73:A76) =SUM(Sheet1!A77:A80) =SUM(Sheet1!A81:A84) =SUM(Sheet1!A85:A88) =SUM(Sheet1!A89:A92) =SUM(Sheet1!A93:A96) =SUM(Sheet1!A97:A100) =SUM(Sheet1!A101:A104) =SUM(Sheet1!A105:A108) =SUM(Sheet1!A109:A112) =SUM(Sheet1!A113:A116) =SUM(Sheet1!A117:A120) =SUM(Sheet1!A121:A124) =SUM(Sheet1!A125:A128) =SUM(Sheet1!A129:A132) =SUM(Sheet1!A133:A136) =SUM(Sheet1!A137:A140) =SUM(Sheet1!A141:A144) =SUM(Sheet1!A145:A148) =SUM(Sheet1!A149:A152) =SUM(Sheet1!A153:A156) =SUM(Sheet1!A157:A160) =SUM(Sheet1!A161:A164) =SUM(Sheet1!A165:A168) =SUM(Sheet1!A169:A172) =SUM(Sheet1!A173:A176) =SUM(Sheet1!A177:A180) =SUM(Sheet1!A181:A184) =SUM(Sheet1!A185:A188) =SUM(Sheet1!A189:A192) =SUM(Sheet1!A193:A196) =SUM(Sheet1!A197:A200) =SUM(Sheet1!A201:A204) =SUM(Sheet1!A205:A208) =SUM(Sheet1!A209:A212) =SUM(Sheet1!A213:A216) =SUM(Sheet1!A217:A220) =SUM(Sheet1!A221:A224) =SUM(Sheet1!A225:A228) =SUM(Sheet1!A229:A232) =SUM(Sheet1!A233:A236) =SUM(Sheet1!A237:A240) =SUM(Sheet1!A241:A244) =SUM(Sheet1!A245:A248) =SUM(Sheet1!A249:A252) =SUM(Sheet1!A253:A256) =SUM(Sheet1!A257:A260) =SUM(Sheet1!A261:A264) =SUM(Sheet1!A265:A268) =SUM(Sheet1!A269:A272) =SUM(Sheet1!A273:A276) =SUM(Sheet1!A277:A280) =SUM(Sheet1!A281:A284) =SUM(Sheet1!A285:A288) =SUM(Sheet1!A289:A292) =SUM(Sheet1!A293:A296) =SUM(Sheet1!A297:A300) =SUM(Sheet1!A301:A304) =SUM(Sheet1!A305:A308) =SUM(Sheet1!A309:A312) =SUM(Sheet1!A313:A316) =SUM(Sheet1!A317:A320) =SUM(Sheet1!A321:A324) =SUM(Sheet1!A325:A328) =SUM(Sheet1!A329:A332) =SUM(Sheet1!A333:A336) =SUM(Sheet1!A337:A340) =SUM(Sheet1!A341:A344) =SUM(Sheet1!A345:A348) =SUM(Sheet1!A349:A352)
- jcctaira
- ベストアンサー率58% (119/204)
マクロのサンプルです。 Sub 集計() Dim I As Integer Dim J As Integer Sheets("Sheet1").Select For I = 1 To Cells(Rows.Count, "A").End(xlUp).Row Step 4 J = J + 1 Sheets("Sheet2").Cells(J, "A") = WorksheetFunction.Sum(Cells(I, "A").Resize(4, 1)) Next I End Sub
- DIooggooID
- ベストアンサー率27% (1730/6405)
マクロを使用しなくても、 =SUM(Sheet1!A1:A4) という数式を設定するだけで良いと思います。 ただ、単にオートフィルコピーをしても、 =SUM(Sheet1!A1:A4) =SUM(Sheet1!A2:A5) =SUM(Sheet1!A3:A6) =SUM(Sheet1!A4:A7) =SUM(Sheet1!A5:A8) となってしまうので、フィルタ機能などを利用して、4つおきに数式を抜き出すと良いです。
補足
回答ありがとうございます。 説明が足りていませんでしたね。 私もそう思ったのですが、整理したいデータが全部で50000行ほどありまして。。 マクロを組んだ方が、効率がよいのではないかと思ったのです。 ご助言ありがとうございました!