2016-10-12 5 views
0

";"で区切られた文字列を分割するのに助けが必要です。この例に示すようにリストを作成します。個々のセルに分割文字列 - VBA関数

  |  A   | 
|----------------------------| 
| Row1 | Name1;Name2;Name3 | 
| Row2 |  Name1  | 
| Row3 |  Name2  | 
| Row4 |  Name3  | 

これをVBA関数でどのように実現できますか?事前に

おかげで、

MD

+3

Split( "Name1; Name2; Name3"、 ";") 'は3要素の配列を返します。その配列の値をワークシートに入れることができます。何を試しましたか? –

+0

なぜ* VBA *であるかは、ワークシート関数で行うことができます。 –

答えて

0

私はランチにわたって非作業関連のコードを書くことが好き:

Sub NamesToList() 
    'Assumes that a cell is selected which contains a string which 
    'looks something like "Name1;Name2;Name3" 
    'The sub splits that list and then puts the values immediately 
    'below the selected cell. Warning: this doesn't check if there is 
    'room for those values and will overwrite existing values with no 
    'warning 

    Dim A As Variant, n As Long, R As Range 
    Set R = Selection 
    A = Split(R.Value, ";") 
    n = UBound(A) 
    Range(R.Offset(1), R.Offset(n + 1)).Value = Application.WorksheetFunction.Transpose(A) 
End Sub 

A1が選択されているときにこのサブを起動した場合、名前はなりますA2:A4に自動的に挿入されます。エラーチェックは行われないので、おそらくこのコードを調整して、そうでないことを確認してください。任意の値を上書きします。

+0

ありがとうジョン!ちょうど私が探していたもの。 –

関連する問題