I am currently trying to split up a row by its quantity then update the "picked" value to reflect this,
For example Product A has a QTY of 5, so 5 lines should be created. Only 3 of these have been picked, so the first 3 new lines can have a picked value of 1, whereas the final 2 lines need to be 0.
Input
Desired Output
I've used an existing VBA script that can do the first part but it's not able to do part 2 (picked). This script simply creates duplicate lines based on the QTY value, but isnt able to manipulate the picked values before insert. So I'm a bit stuck, hopefully someone can help? I appreciate this may need a total rewrite.
Sub CopyData()
'Updateby Extendoffice
Dim xRow As Long
Dim VInSertNum As Variant
Dim Start As Long
xRow = 2
Application.ScreenUpdating = False
Do While (Cells(xRow, "A") <> "")
VInSertNum = Cells(xRow, "B")
Cells(xRow, "B").Value = 1
If ((VInSertNum > 1) And IsNumeric(VInSertNum)) Then
Range(Cells(xRow, "A"), Cells(xRow, "H")).Copy
Range(Cells(xRow + 1, "A"), Cells(xRow + VInSertNum - 1, "H")).Select
Selection.Insert Shift:=xlDown
xRow = xRow + VInSertNum - 1
End If
xRow = xRow + 1
Loop
Application.ScreenUpdating = False
End Sub
Incorrect Output
EDIT ---------------_
Thank you for the help, I've tried to adjust the code you sent for the final data but it's not quite working for me, In the final sheet column 8,9,10 are what is discussed above - with data that just needs to be copied either side, what am I missing?
Sub TestMacro()
Dim i As Long
Dim lr As Long
Dim dict As Object
Dim temparr As Variant 'For duplicates
Dim newsheet As Worksheet
Set dict = CreateObject("Scripting.Dictionary")
With Sheets("ExchequerReport") 'Change as needed
lr = .Cells(.Rows.Count, 1).End(xlUp).Row
For i = 2 To lr
If Not dict.exists(.Cells(i, 8).Value) Then
dict.Add .Cells(i, 1).Value, .Cells(i, 2).Value, .Cells(i, 3).Value, .Cells(i, 4).Value, .Cells(i, 5).Value, .Cells(i, 6).Value, .Cells(i, 7).Value, .Cells(i, 8).Value, Array(.Cells(i, 9).Value.Cells(i, 10).Value.Cells(i, 11).Value.Cells(i, 12).Value.Cells(i, 13).Value.Cells(i, 14).Value.Cells(i, 15).Value.Cells(i, 16).Value.Cells(i, 17).Value.Cells(i, 18).Value.Cells(i, 19).Value.Cells(i, 20).Value.Cells(i, 21).Value)
Else
'Not sure what to do about dupes, adding quantities together
temparr = dict(.Cells(i, 8).Value)
temparr(0) = dict(.Cells(i, 8).Value)(0) + .Cells(i, 9).Value
temparr(1) = dict(.Cells(i, 8).Value)(1) + .Cells(i, 10).Value
dict(.Cells(i, 1).Value) = temparr
End If
Next i
End With
Set newsheet = ThisWorkbook.Sheets.Add
With newsheet
Dim key As Variant
Dim j As Long
.Cells(1, 1).Value = "Model Helper"
.Cells(1, 2).Value = "Dealer Helper"
.Cells(1, 3).Value = "Account Code"
.Cells(1, 4).Value = "Dealer"
.Cells(1, 5).Value = "SOR HELPER"
.Cells(1, 6).Value = "SOR"
.Cells(1, 7).Value = "IS GREATER THAN 0"
.Cells(1, 8).Value = "Stock Code"
.Cells(1, 9).Value = "Qty on Order"
.Cells(1, 10).Value = "QTY Picked"
.Cells(1, 11).Value = "QTY Needed"
.Cells(1, 12).Value = "QTY on POR"
.Cells(1, 13).Value = "US CODE"
.Cells(1, 14).Value = "Location"
.Cells(1, 15).Value = "Order Date"
.Cells(1, 16).Value = "Availability Date"
.Cells(1, 17).Value = "Del Request"
.Cells(1, 18).Value = "ODM Promise"
.Cells(1, 19).Value = "LOAD NEXT CONTAINER"
.Cells(1, 20).Value = "Del Promise"
.Cells(1, 21).Value = "Category"
i = 2
For Each key In dict
For j = 1 To dict(key)(0)
.Cells(i, 1).Value = key
.Cells(i, 2).Value = key
.Cells(i, 3).Value = key
.Cells(i, 4).Value = key
.Cells(i, 5).Value = key
.Cells(i, 6).Value = key
.Cells(i, 7).Value = key
.Cells(i, 8).Value = key
.Cells(i, 9).Value = 1
.Cells(i, 11).Value = key
.Cells(i, 12).Value = key
.Cells(i, 13).Value = key
.Cells(i, 14).Value = key
.Cells(i, 15).Value = key
.Cells(i, 16).Value = key
.Cells(i, 17).Value = key
.Cells(i, 18).Value = key
.Cells(i, 19).Value = key
.Cells(i, 20).Value = key
.Cells(i, 21).Value = key
If j <= dict(key)(1) Then
.Cells(i, 10).Value = 1
Else
.Cells(i, 10).Value = 0
End If
i = i + 1
Next j
Next key
End With
End Sub