# Sum Formula for selective values.

Hello!

Column A has a list of different repetitive codes and Column B has a corresponding \$\$ for each code. I need a function that will give me only one \$\$ value for each code and will exclude all others. Please refer to the attached file.
Sum-Formula-for-selected-values.xlsx
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
HI,

pls try as Array formula (ctrl-Shft-Enter)

=SUM(B2:B14/COUNTIF(A2:A14,A2:A14))

Regards
0
Author Commented:
Sorry, I missed a step and  explained it wrong. I don't need an overall "Total".  Column "C" should have  a \$\$ value for each code (but only one, all others need to be excluded). Please refer to the attached file.  Thank you!!
Sum-Formula-for-selected-values.xlsx
0
Commented:
0
Author Commented:
The suggested formula did not work. The attached file has more data for you to better understand what I am looking for. I filtered on the first code to show you that your formula is still pulling both \$\$ amounts. And it should only be referencing one. Please advise! Thank you!
Sum-Formula-for-selected-values.xlsx
0
Commented:
Use this formula...

=if(countif(A\$1:A2,A2)=1,B2,"")

Simply drag this and it will do what you are looking for..

Saurabh...
0
Commented:
Also one quick point since you have lot of data so i won't use formulas in it since excel is growing crazy when i applied formula in the range..I will rather use a code..to do this..

Enclosed the code and your workbook..Post i have run the code...

``````Sub check()
Dim rng As Range, cell As Range
Dim lrow As Long, r As Range

lrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set rng = Range("A2:A" & lrow)
For Each cell In rng
Set r = Range("A2:A" & cell.Row)
If Application.WorksheetFunction.CountIf(r, cell.Value) = 1 Then
cell.Offset(0, 2).Value = cell.Offset(0, 1).Value
Else
cell.Offset(0, 2).Value = ""
End If

Next cell
End Sub
``````

This is based on the same logic of the formula which i gave to you...

Your workbook post the code has run...

Saurabh...
Sum-Formula-for-selected-values.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.