Modify code so that it takes the results of the code and multiplies it by a value

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. 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
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
got it
Code:
Sub Find_Parent_Qty()
'Find Parent Qty and my Qty (GHyeman)

Dim ws As Worksheet
Dim st1, st2 As String

Set ws = ActiveSheet

cont = Application.WorksheetFunction.CountA(ws.Range("f:f"))

    For a = 4 To cont
        If ws.Cells(a, 4) = "" Then GoTo nxt
            st1 = ws.Cells(a, 4)
    For b = a - 1 To 1 Step -1
        st2 = ws.Cells(b, 6)
    If st1 = st2 Then
    ws.Cells(a, 11) = ws.Cells(a, 10) * ws.Cells(b, 10)
    
    GoTo nxt

    End If

    Next b
nxt:
    Next a
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top