Hello, I am trying to create a Macro to Add Two values when the values in another cell Match
Here is an example:
A B
Amount Invoice Number
$509.00 #46402418 Same #
$450.00 #46417335
$450.00 #46604515
$450.00 #46497732
($59.00) #46402418 Same #
$600.00 #46651112
$800.00 #46653760
New Row $450.00 #46402418
In this case I have two columns A with the Price and B with the invoice number. I need a Macro that when the Invoice number match in column B Both values from Column A get added. In this case $509 + ($-59) = $450.
Additionally I would need to clean up the sheet, delete both values that have been added and only leave the new Column with the total.
Re: Add two cells when values in another cell match
is it possible that after you delete the values that were added, same invoice number could appear again?
And do you want results in different columns than A and B?
It would help if you can attach a sample file with your data structure so we can write the macro into it and test it.
1. Click on the * Add Reputation if you think this helped you
2. Mark your thread as SOLVED when question is resolved
A starter demonstration to paste to the (before) worksheet module :
PHP Code:
Sub Demo1() Dim L&, R&, V, W L = Me.UsedRange.Rows.Count With CreateObject("Scripting.Dictionary") For R = 2 To L V = Me.UsedRange.Rows(R).Value2 If .Exists(V(1, 4)) Then W = .Item(V(1, 4)) W(1, 3) = W(1, 3) + V(1, 3) .Item(V(1, 4)) = W Else .Add V(1, 4), V End If Next If .Count < L - 1 Then Me.UsedRange.Rows(2 + .Count & ":" & L).Clear Me.UsedRange.Rows(2).Resize(.Count).Value2 = Application.Index(.Items, 0) End If .RemoveAll End With End Sub
Do you like it ? So thanks to click on bottom left star icon « ★ Add Reputation » !
Bookmarks