重要なお知らせ

「教えて! goo」は2025年9月17日(水)をもちまして、サービスを終了いたします。詳細はこちら>

電子書籍の厳選無料作品が豊富!

【やりたい事】
以下画像にて、A列のかきくけこ3行を、C列のあいうえおの最終行の次に
切取りをして、貼付したいです

貼付方法や手順は、指定はありません。以下コードは自分が思いついただけのものです
【条件】
・xの数は、常に変動
・水色は、デフォルトである、データとします
⇒ただし、常にあいうえおやかきくけこの数へ変更します
・A列、上と下のセルの間は常に8セル

より簡潔なコードがあれば教えて下さい
宜しくお願いします

【コード】
Sub かきくけこ移動()

Dim lastrow1 As Long
lastrow1 = Cells(1, 1).End(xlDown).Row

Dim lastrow2 As Long
lastrow2 = Cells(Rows.Count, "c").End(xlUp).Row

Dim lastrow3 As Long
lastrow3 = Cells(Rows.Count, "a").End(xlUp).Row

For i = (lastrow1 + 9) To lastrow3

If Cells(i, 1) <> "x" Then

Cells(i, 3) = Cells(i, 1)

End If

Next i


Cells(lastrow1 + 9, "c").CurrentRegion.Cut

Cells(lastrow2 + 1, "c").Select

ActiveSheet.Paste


End Sub

「【マクロ 画像あり】セル範囲の移動につい」の質問画像

A 回答 (1件)

ちょっと、短くなるだけですが。



Sub かきくけこ移動()

Dim lastrow1 As Long
lastrow1 = Cells(1, 1).End(xlDown).Row

Dim lastrow2 As Long
lastrow2 = Cells(Rows.count, "c").End(xlUp).Row

Dim lastrow3 As Long
lastrow3 = Cells(Rows.count, "a").End(xlUp).Row
Dim i As Long
Dim j As Long
j = lastrow2 + 1
For i = (lastrow1 + 9) To lastrow3

If Cells(i, 1) <> "x" Then

Cells(j, 3) = Cells(i, 1)
j = j + 1
End If

Next i

End Sub
    • good
    • 0
この回答へのお礼

みたこともない、すごい、技とだと思いました
j = j + 1 ですね。ご指南ありがとうございます

お礼日時:2025/03/18 01:06

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!

このQ&Aを見た人はこんなQ&Aも見ています


このQ&Aを見た人がよく見るQ&A