Excelには2列のデータがあります。1 つは値で、もう 1 つはキー文字列のセミコロン区切りのリストです。この 2 番目の列を分割して、値を個々のキーと個々のキーと値のペアとして関連付ける必要があります。
入力:Value1 "key1;key2"
出力
Value1 Key1
Value1 Key2
以下のサンプルコードを試してください
Sub sample()
Dim strValue As String
s = 2
For i = 2 To Range("A" & Rows.Count).End(xlUp).Row
strValue = Range("B" & i).Value
retval = Split(strValue, ";")
For j = LBound(retval) To UBound(retval)
Range("C" & s) = Range("A" & i).Value
Range("D" & s) = retval(j)
s = s + 1
Next
Next
End Sub
これにより、更新/分割されたリストが新しいワークシートに配置されます。
Sub SplitKeyVals()
Dim wsMe As Worksheet: Set wsMe = ActiveSheet
Dim wsNew As Worksheet
Dim rngKeys As Range
Dim cl As Range
Dim keyVals() As String
Dim k As Variant
Dim r As Long: r = 1
Dim myDelimiter as String
Set wsNew = Worksheets.Add(Before:=ActiveSheet) '## Modify as needed ##'
Set rngKeys = wsMe.Range("A2:A10") '## Modify as needed ##'
'## We will use this delimiter value later ##'
myDelimiter = ";"
'## Iterate over each cell in rngKeys.Cells ##'
For Each cl In rngKeys.Cells
'## Use the Split function to split a delimited string in to
' an array, so we can iterate over the values. '
keyVals = Split(cl.Offset(0, 1).Value, myDelimiter)
'## Now that the values are in array, iterate over the
' array items: '
For Each k In keyVals
'## Do something with this information ##'
wsNew.Cells(r, 1) = cl.Value
wsNew.Cells(r, 2) = k
'## Increase the destination row for output ##'
r = r + 1
Next
Next
End Sub