LoginSignup
0
1

VBA 文字列をまとめてから消す

Posted at

アクティブセルから並んでるデータをまとめて、その後行削除する
実行前
前.png
実行後
後.png

.vba
Option Explicit
Sub Main()

#文字列の取得
	Dim w1, w2, w3, w4, w5, w6, w7, w8, w9, w0 As Variant
	w1 = ActiveCell.Value
	w2 = ActiveCell.Offset(1, 0).Value
	w3 = ActiveCell.Offset(2, 0).Value
	w4 = ActiveCell.Offset(3, 0).Value
	w5 = ActiveCell.Offset(4, 0).Value
	w6 = ActiveCell.Offset(5, 0).Value
	w7 = ActiveCell.Offset(6, 0).Value
	w8 = ActiveCell.Offset(7, 0).Value
	w9 = ActiveCell.Offset(8, 0).Value
	w0 = ActiveCell.Offset(9, 0).Value

#結合
	Dim connectWord As String
	connectWord = w1 & w2 & w3 & w4 & w5 & w6 & w7 & w8 & w9 & w0
	ActiveCell.Value =  connectWord

#消去
	Dim rowsNo As Integer
	rowsNo = ActiveCell.Row +1
	Dim i As Integer
	For i = 1 To 9
		Rows(rowsNo).Delete
	Next i
End Sub

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