区切り文字で区切って配列化

文字列を区切り文字で区切って、配列に入れます。
区切り文字は、カンマ、セミコロン、改行など何でも使えます。

Sub SeparatingStr()
	Dim spastr As Variant
	Dim idx As Long

	' カンマ区切り
	spastr = Split(Range("B1"), ",")

	Debug.Print "----------------"
	Debug.Print Range("A1") & " : 件数 = " & (UBound(spastr) - LBound(spastr) + 1)

	For idx = LBound(spastr) To UBound(spastr)
		Debug.Print spastr(idx)
	Next idx


	' セミコロン区切り
	spastr = Split(Range("B2"), ";")

	Debug.Print "----------------"
	Debug.Print Range("A2") & " : 件数 = " & (UBound(spastr) - LBound(spastr) + 1)

	For idx = LBound(spastr) To UBound(spastr)
		Debug.Print spastr(idx)
	Next idx


	' 改行区切り
	spastr = Split(Range("B3"), vbLf)

	Debug.Print "----------------"
	Debug.Print Range("A3") & " : 件数 = " & (UBound(spastr) - LBound(spastr) + 1)

	For idx = LBound(spastr) To UBound(spastr)
		Debug.Print spastr(idx)
	Next idx
End Sub

コメント