Excel2000 VBA 選択範囲をInputBoxで入力した値で展開する [Excel2000 VBA独習]
Excel2000 VBA 選択範囲をInputBoxで入力した値で展開する
例 ABCD#123 の文字列をInputBoxに # を入力し、#を区切りキーワードにして展開する
結果 ABCD 123
Sub 選択範囲列を指定した文字で文字列を展開()
'
'選択範囲列を指定した文字で文字列を展開する
'
'テストバージョン
Dim txt_column As Variant
Dim txt As Variant
Dim i As Integer
Dim j As Integer
Dim x As Integer
Dim cell_row_top As Integer
Dim cell_row_bottom As Integer
Dim cell_count As Integer
Dim cell_column As Integer
Dim myIB As Variant
x = 0 '0で選択範囲から展開 1で右に展開
j = 0
'選択範囲を調べる
cell_column = Selection.Column
cell_row_top = Selection.ROW
cell_count = Selection.Rows.count
'InputBoxで区切り文字を取得
myIB = Application.InputBox(Title:="指定文字で文字列を展開", prompt:="区切りキー文字を入力してください", Default:="", Left:=100, Top:=100, Type:=2)
'Split関数 for each で展開
For i = cell_row_top To cell_row_top + cell_count - 1
txt_column = Split(Cells(i, cell_column).Value, myIB)
For Each txt In txt_column
Cells(i, cell_column + j + x) = txt
j = j + 1
Next
j = 0
Next i
End Sub
コメント 0