如何根据两列逗号分隔值插入多个logging

我试图创build基于逗号分隔值的多个单元格的logging。

拿着它:

Handle | Title | Color | Size | Price | | | | (0-04/06-08) --------------------------------------------------------------------------- Jovani-JVN86957 | Jovani | Black, | 0, 02, | $199 (if size > 06 then +15) JVN86957 | Red, White | 04, 06, 08 | 

我想要做的是颜色和大小列生成新的logging,同时包括处理和价格(也可能,但不是必须有价格变化的基础上,尺寸值,即:大小0-4 = $ 199和大小6-8 = $ 219)

转到这个:

 Handle Title Color Size Price(0 04/06 08 +$15) Jovani-JVN86957 Jovani-JVN86957 Black 0 $199 Jovani-JVN86957 Black 2 $199 Jovani-JVN86957 Black 4 $199 Jovani-JVN86957 Black 6 $199 +$15 = $214 Jovani-JVN86957 Black 8 $199 +$15 = $214 Jovani-JVN86957 Red 0 $199 Jovani-JVN86957 Red 2 $199 Jovani-JVN86957 Red 4 $199 Jovani-JVN86957 Red 6 $199 +$15 = $214 Jovani-JVN86957 Red 8 $199 +$15 = $214 Jovani-JVN86957 White 0 $199 Jovani-JVN86957 White 2 $199 Jovani-JVN86957 White 4 $199 Jovani-JVN86957 White 6 $199 +$15 = $214 Jovani-JVN86957 White 8 $199 +$15 = $214 

任何帮助将非常感激。

这里有一个方法是通过使用多个循环来更加强悍一些。

 Sub SplitEntries() Dim rng As Range Set rng = Range("A2:A5") 'Copy over header Range("G1:K1").Value = Range("A1:E1").Value Dim sizeSplit As Variant Dim colorSplit As Variant Dim rowCntr As Integer: rowCntr = 2 'Loop thru range For Each cell In rng Range("H" & rowCntr).Value = cell.Offset(0, 1).Value 'Get all the colors colorSplit = Split(cell.Offset(0, 2), ",") 'Loop through each color For i = LBound(colorSplit) To UBound(colorSplit) 'Get all the sizes sizeSplit = Split(cell.Offset(0, 3), ",") 'Loop through each size For j = LBound(sizeSplit) To UBound(sizeSplit) Range("G" & rowCntr).Value = cell.Value Range("I" & rowCntr).Value = Trim(colorSplit(i)) Range("J" & rowCntr).Value = Trim(sizeSplit(j)) 'Range("K" & rowCntr).Value = cell.Offset(0, 4).Value If Trim(sizeSplit(j)) < 6 Then Range("K" & rowCntr).Value = cell.Offset(0, 4).Value Else Range("K" & rowCntr).Value = cell.Offset(0, 4).Value + 15 End If rowCntr = rowCntr + 1 Next j Next i Next cell End Sub 

起始数据如下所示:

在这里输入图像说明

结果被放在这样的新的列:

在这里输入图像说明