Excel:需要一个公式,可以获得一个范围内的唯一值的总量

例如:A10 = 111,A11 = 101,A12 = 111,A13 = 4,A14 = 101,A15 =空白。 总共有3个独特的值。 我需要一个可以计算所有唯一值的单元格中的dynamic公式。 空白将在设定范围内,不应包含在总数中。 谢谢。

来自微软:

在单元格B2:B10(不得包含空白单元格)中计算唯一文本和数字值的数量(7)

=SUM(IF(FREQUENCY(MATCH(B2:B10,B2:B10,0),MATCH(B2:B10,B2:B10,0))>0,1)) 

http://office.microsoft.com/en-us/excel-help/count-occurrences-of-values-or-unique-values-in-a-data-range-HP003056118.aspx

这可以在VBA中完成: http : //www.google.com/search? q = VBA+ distinct

如果您只需要一次这样做,您可以通过几个步骤进行半手动操作:

1)对值进行sorting(比如在B10-B15中)

2)在下一列中,在每个单元格中使用此公式: =IF(C10<>B9,C10,"") 。 (只显示值,如果它不等于它上面的那个。)这将给你独特的价值观。

“总量”是指不同值的总和还是数值? 无论哪种方式,你可以用计算列的值来做到这一点。

你可以使用这个VBA代码,这些代码很好的评论你的理解。

Sub sample_CntDist()
'
' Counting Distinct numbers, not counting blank values presenting count distinct in a cell Macro
'
'
Columns("A:A").Select 'select the column which have numbers
Selection.Copy 'copy the selection
Sheets("Sheet2").Select 'select a new sheet
Range("A1").Select 'select first cell
ActiveSheet.Paste 'paste the copied data
Application.CutCopyMode = False
ActiveSheet.Range("$A$1:$A$18").RemoveDuplicates Columns:=1, Header:=xlNo 'remove duplicates
Range("B1").Select 'select cell b1
ActiveCell.FormulaR1C1 = "=COUNTIF(C[-1],""<>"")" 'count distinct number excluding blanks
Sheets("Sheet1").Select 'select original sheet
Range("C2").Select 'select cell c2
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "count distinct " 'give a caption for the result
Range("D2").Select 'select cell d2
Sheets("Sheet2").Select 'select the temp sheet
Selection.Copy 'copy the distinct count
Sheets("Sheet1").Select 'select and paste the result as values
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Sheet2").Select
ActiveWindow.SelectedSheets.Visible = False 'hide temp sheet
End Sub