Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default Sum Unique Values Across SpecialCellType Visible Range.

I am trying to sum only the unique values that are visible in a column.

I have an autofilter applied to my worksheet that is hiding dates that are
outside of a certain range. In column "Reference No" there are a list of ID
values, some of which repeat. If a value repeats, I want to only count the
related transaction value, stored in the same row of a different cell, only
once.

The following code effectively sums unique values across all rows. However,
I need it to work only within the range of visible cells.

Is this possible using the autofilter, or do I need to add a second argument
to my "IF" statement regarding the date range (would prefer not to, since
this would inevitably be slower).




code:
--------------------------------------------------------------------------------


Set rng2 = .Range(.Cells(1, 1), .Cells(2 ^ 16,
rng.Count).SpecialCells(xlCellTypeVisible).End(xlU p))

For i = 1 To rng.Count
If cName(i) = "Reference No" Then
Set rng2 = .Range(.Cells(1, i), .Cells(2 ^ 16, i).End(xlUp))
For j = 2 To rng2.Count
istrue = True
If .Cells(j, i).Value < .Cells(j + 1, i).Value _
And .Cells(j, tDate).Value LowYear Then
totalvalue = totalvalue + .Cells(j, i + 1)
istrue = False
End If
Next j
End If
Next i
--------------------------------------------------------------------------------

  #2   Report Post  
Posted to microsoft.public.excel.programming
ste ste is offline
external usenet poster
 
Posts: 6
Default Sum Unique Values Across SpecialCellType Visible Range.

Hi, this is a function I use in one of my add-ins



Function vertSUM(aTable As Range, aCell As Range, Offset As Integer) As
Double
Dim tmp As Range
Dim A As Long

Set tmp = aTable.Find(aCell.Text, LookIn:=xlValues, Lookat:=xlWhole)
If Not tmp Is Nothing Then
A = tmp.Row

Do
vertSUM = vertSUM + tmp.Offset(, Offset).Value

Set tmp = aTable.Find(aCell.Text, tmp, LookIn:=xlValues,
Lookat:=xlWhole)
If tmp Is Nothing Then Exit Function
Loop While tmp.Row < A

End If

End Function


-----------------------

A B
1 a =vertsum($A$7:$B$10;$A1;1) '
2
3
4
5
6 ID VALUE 'values you can filter
7 a 2
8 b 2
9 a 2
10 b 2


Regards,
ste

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting the number of unique values within a range SiH23 Excel Discussion (Misc queries) 5 October 30th 08 06:36 PM
count unique values in a filtered range ChrisR Excel Worksheet Functions 2 July 1st 08 07:02 PM
Unique values from date range tqm1 Excel Discussion (Misc queries) 1 June 28th 07 08:04 AM
How do I get the unique values from a range? DaveO Excel Worksheet Functions 13 January 13th 06 12:55 AM
Display unique values in a range. future Excel Programming 5 January 29th 04 11:24 PM


All times are GMT +1. The time now is 02:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"