» Add unique values using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - Custom Functions , Printing in VBA
VERSION - All Microsoft Excel Versions
The custom function below adds the unique values only from a given range:
Function SumUniqueValues(InputRange As Range) as Double
Dim cl As Range, UniqueValues As New Collection, uValue As Variant
Application.Volatile
On Error Resume Next
For Each cl In InputRange
UniqueValues.Add cl.Value, CStr(cl.Value)
Next cl
On Error GoTo 0
SumUniqueValues = 0
For Each uValue In UniqueValues
SumUniqueValues = SumUniqueValues + uValue
Next uValue
End Function
Example:
=SumUniqueValues(A1:A100) will add the unique values in the range A1:A100.
Book Store:
Recommended Books:
- Microsoft Excel VBA Programming for the Absolute Beginner
- Microsoft Outlook 2002 for Dummies
- AWAKEN THE GIANT WITHIN : HOW TO TAKE IMMEDIATE CONTROL OF YOUR MENTAL, EMOTIONAL, PHYSICAL AND FINANCIAL
- Accounting Principles, with CD, 6th Edition
- Keys to Reading an Annual Report (Barron's Business Keys)
- Final Accounting: Ambition, Greed and the Fall of Arthur Andersen
No comments have been submitted.

