sollten Dieser Code sein, was Sie suchen, nimmt das Verfahren ExpandData(String, String, String)
die Startspalte für den Satz von Daten (in diesem Fall „A“) für den ersten Parameter, die End-Spalte für den Satz von Daten als zweiten Parameter kopieren (in diesem Fall "D") und schließlich die Spalte mit dem Datensatz, der durch Komma getrennt ist (hier "E").
Sie sollten es wahrscheinlich erweitern, so dass es auch eine Startzeile oder einfach eine AddIn Formel Sache, wo es einen Bereich und eine Spalte dauert.
Hoffe, das hilft.
Sub ExpandDat()
ExpandData "A", "D", "E"
End Sub
Sub ExpandData(start_range As String, end_range As String, comma_column As String)
Const FirstRow = 1
Dim LastRow As Long
LastRow = Range(start_range & CStr(Rows.Count)).End(xlUp).Row
' Get the values from the worksheet '
Dim SourceRange As Range
Set SourceRange = Range(start_range & CStr(FirstRow) & ":" & end_range & CStr(LastRow))
' Get the comma seperated values as a different set of values '
Dim CommaRange As Range
Set CommaRange = Range(comma_column & CStr(FirstRow) & ":" & comma_column & CStr(LastRow))
' Get the values from the actual values '
Dim Vals() As Variant
Vals = SourceRange.Value
' We need to know the upper and lower bounds of the second dimension in the Vals Array '
Dim lower As Integer
Dim upper As Integer
lower = LBound(Vals, 2)
upper = UBound(Vals, 2)
' Get the comma seperated values '
Dim Commas() As Variant
Commas = CommaRange.Value
' Loop through the rows in the array and split each comma-delimited list of items and put each on its own row '
Dim ArrIdx As Long
Dim RowCount As Long
For ArrIdx = LBound(Commas, 1) To UBound(Commas, 1)
Dim CurrList As String
CurrList = Replace(Commas(ArrIdx, 1), " ", "")
' Split the Comma set into an array '
Dim ListItems() As String
ListItems = Split(CurrList, ",")
' For each value in the Comma Seperated values write the output '
Dim ListIdx As Integer
For ListIdx = LBound(ListItems) To UBound(ListItems)
' Loop through the values in our source range and output them '
For Idx = lower To upper
Range(start_range & CStr(FirstRow + RowCount)).Offset(0, Idx - 1).Value = Vals(ArrIdx, Idx)
Next Idx
Range(comma_column & CStr(FirstRow + RowCount)).Value = ListItems(ListIdx)
RowCount = RowCount + 1
Next ListIdx
Next ArrIdx
End Sub
Was ist der Code, den Sie gerade verwenden? –