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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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