0
0

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 3 years have passed since last update.

Excelで複数行の値を統合するVBAマクロ

Posted at

Excelで、改行のあるテキストを貼り付けた時、PPTなどからコピペした時、複数行に値が分かれてしまって困ることはありませんか。
Qiita Excel Image2.png
F2を押して数式バーに貼り付ければ手順的には良いのですが、数が多いとイラッとしますよね。
以下は、7行のセルを1つ目のセルに統合するサンプルです。

Sub IntegCell()
    Dim FromCell As String
    Dim ToRange As Range
    FromCell = ActiveCell.Text
    ' 2行目から7行目を選択し、1行目に統合 行数を調整したい場合はここを変更
    For Each ToRange In ActiveCell.Range("A2:A7")
        If ToRange.Text <> "" Then
            FromCell = FromCell & vbLf & ToRange.Text
            ToRange.Clear
        End If
    Next ToRange
    ActiveCell.Range("A1").Value = FromCell
End Sub
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?