Finding the Sum of the Values Within Unique Cells Based on 2 Criteria in a Range

psmi123

New Member
Joined
Jul 10, 2018
Messages
16
I want to find the sum of the range within the sector within the zone but only summing unique values. For example, I want to find the sum of the Codes within Sector Ice Cream, Zone 1. However I don't want to count duplicates within that range. $63 Dollars should be the total of Sector Ice Cream, Zone 1 because it removes duplicate values within that range. $103 should be the total of Sector Ice Cream, Zone 5. What formula would be the best way to do this. Thank you in advance for your help!




SectorZoneCode 1 $Code 2 $Code 3 $
Ice Cream1$30$20$5
Ice Cream1$20$30$8
Ice Cream2$40$26$46
Ice Cream3$24$74$27
Ice Cream4$94$27$83
Ice Cream5$55$5$43
Ice Cream5$5$55$5
Ice Cream5$43$5$55
Frozen Yogurt1$3$2$1
Frozen Yogurt1$3$4$5
Frozen Yogurt2$4$3$2
Frozen Yogurt3$5$6$8

<colgroup><col span="5"></colgroup><tbody>
</tbody>

<colgroup><col span="5" style="text-align: center;"></colgroup><tbody>
</tbody>
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Give this macro a try...
Code:
[table="width: 500"]
[tr]
	[td]Sub UniqueZoneAmounts()
  Dim Coff As Long, LastRow As Long, LastCol As Long, Ar As Range
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
  Range("B2:B" & LastRow).Value = Evaluate("IF(B2:B" & LastRow & "=B1:B" & LastRow - 1 & ","""",B2:B" & LastRow & ")")
  On Error GoTo NoDupes
  Application.ScreenUpdating = False
  For Each Ar In Range("B1:B" & LastRow).SpecialCells(xlBlanks).Areas
    For Coff = 1 To LastCol - 2
      Ar.Offset(-1, Coff) = Application.Sum(Ar.Offset(-1, Coff).Resize(Ar.Count + 1))
    Next
  Next
  Range("B2:B" & LastRow).SpecialCells(xlBlanks).EntireRow.Delete
NoDupes:
  Application.ScreenUpdating = True
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Is there a formula instead that I can use?
Probably, but I am not much of a formula guy and I would expect the series of formulas that you would need to be somewhat complex (you have to retrieve the unique Zones and their sectors, then you have to sum up the values from each code for the zones whether duplicate or not. I am sure one of our expert formula volunteers will eventually weigh in with a solution for you.
 
Upvote 0

Forum statistics

Threads
1,215,824
Messages
6,127,107
Members
449,358
Latest member
Snowinx

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