Subtracting one value from an existing value based on a cell description

Mrnewb

New Member
Joined
Oct 7, 2013
Messages
13
Hi All, Thanks in advance for any help. I am trying to get a code to Subtract a value from a cell on another sheet using another cell name as the trigger. IE if sheet 1 cell A1 = 12345 the code must look up 12345 on sheet 2 and subtract sheet 1 cell 2 from sheet 2 say B8 (whichwere row it finds 12345).

I have tried to use this code which works unless I have the same trigger cell name - it wont subtract the figure twice? I Hope this makes sense.

Code:
Dim Rng3 As Range, Dn3 As Range
Dim Dic3 As Object
With Sheets("Report")
    Set Rng3 = .Range(.Range("A6"), .Range("A" & Rows.Count).End(xlUp))
End With
Set Dic3 = CreateObject("scripting.dictionary")
    Dic3.CompareMode = vbTextCompare
    
        For Each Dn3 In Rng3
            Dic3(Dn3.Value) = Dn3.Offset(, 7) 'OPERATOR/booked out QTY'
        Next
With Sheets("Planning ")
    Set Rng3 = .Range(.Range("A7"), .Range("A" & Rows.Count).End(xlUp))
End With
For Each Dn3 In Rng3
    If Dic3.exists(Dn3.Value) Then
    If Dn3.Offset(, 2) <> "Order quantity" Then
    If Dn3.Offset(, 2) <> "Production cell" Then
    If Dn3.Offset(, 3) <> "Outstanding order quantity" Then
    If Dn3.Offset(, 3) <> "" Then
    
        Dn3.Offset(, 3) = Dn3.Offset(, 3) - Dic3.Item(Dn3.Value)
        
        
    End If
    End If
    End If
    End If
    End If
Next
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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