使用Excel / VB根据父产品列表创build产品变体列表

我正在使用产品CSV导入套装插件运行一个Woocommerce商店。 我需要先上传一份母公司产品清单,然后再列出产品变化清单。 创build第二个列表是相当费力的,所以我正在寻找一种方法来自动生成这个列表尽可能多。

下面是一个简短的父母产品列表: 在这里输入图像说明

与父母产品实际列表将包含更多的产品特征。

这就是产品变化的结果应该如何: 在这里输入图像说明

正如你所看到的,可以看到产品变体(孩子)内部产品的所有产品特性,只有一个尺寸和颜色variables。 如果一个孩子sku也会自动生成,那将会很好。

我希望在不同的工作表中生成输出数据(产品变体)(与父产品列表分开)。

有没有人有任何想法如何在Excel中做到这一点? 我不是Excel向导,所以我希望你能给我一些关于如何实现你的解决scheme的指导。

这里的逻辑是读取每一行,直到find一个空行,然后拆分颜色和大小。 然后创build一个外部循环的颜色和内部循环的大小(这将处理所有变化)。 您还需要一个variables来保存SKU计数器,并在产品变化完成后重置。 以下将帮助您开始:

 Sub ProductVariations() Dim productRow As Long, variationRow As Long Dim size As String Dim color As String Dim skuCounter As Integer Dim skuChild As String Dim sizeArray() As String Dim colorArray() As String Dim sizeElement As Variant Dim colorElement As Variant Dim productsSheet As Worksheet Dim variationsSheet As Worksheet productRow = 2 variationRow = 2 Set productsSheet = ActiveWorkbook.Sheets(1) Set variationSheet = ActiveWorkbook.Sheets(2) 'loop through each row until a blank row is found While productsSheet.Cells(productRow, 1).Value <> "" 'get the size and color values for the current row size = productsSheet.Cells(productRow, 3) color = productsSheet.Cells(productRow, 4) 'make sure a size and color exists then process If Len(size) > 0 And Len(color) > 0 Then 'reset the sku counter skuCounter = 0 'split the size and color into arrays sizeArray = Split(size, "|") colorArray = Split(color, "|") 'loop through each size For Each sizeElement In sizeArray 'loop through each color For Each colorElement In colorArray 'increment the child counter for this variation skuCounter = skuCounter + 1 'set the appropriate cells in the variations sheet (you have some more work to do here skuChild = productsSheet.Cells(productRow, 2).Value & "-" & skuCounter variationSheet.Cells(variationRow, 1).Value = productsSheet.Cells(productRow, 1) variationSheet.Cells(variationRow, 3).Value = skuChild 'increment the variation row so the next variation goes in the next row variationRow = variationRow + 1 Next colorElement Next sizeElement End If 'very important increment the next row or only the first row will ever get processed productRow = productRow + 1 Wend End Sub