Вы можете использовать этот код 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