gheyman
Well-known Member
- Joined
- Nov 14, 2005
- Messages
- 2,347
- Office Version
- 365
- Platform
- Windows
The code below runs fine. But I also want to use it to take the results (Dn.Offset(, 6).Value = R.Offset(, 5).Value) and multiplies R.Offset by the value in in the current row.
Code:
Sub Find_Parent_Quantity()
'Find the Parent's Quantity and place it in Column K
Dim Rng As Range, Dn As Range, n As Long, R As Range
Set Rng = Range(Range("E2"), Range("E" & Rows.Count).End(xlUp))
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
For Each Dn In Rng
If Not .exists(Dn.Value) Then
.Add Dn.Value, Dn
Else
Set .Item(Dn.Value) = Union(.Item(Dn.Value), Dn)
End If
Next Dn
For Each Dn In Rng
If .exists(Dn.Value - 1) Then
If Not .Item(Dn.Value - 1) Is Nothing Then
For Each R In .Item(Dn.Value - 1)
If R.Row < Dn.Row Then
'Dn.Offset is Which column, relative to the column it searching, to place the result
Dn.Offset(, 6).Value = R.Offset(, 5).Value
End If
Next R
End If
End If
Next Dn
End With
End Sub