Conditional counting formula 2 times or more

Excelpromax123

Board Regular
Joined
Sep 2, 2021
Messages
167
Office Version
  1. 2010
Platform
  1. Windows
Hello everyone. I need a VBA formula to count numbers that appear 2 or more times and subtract 1 (for example, counting the number 5 out 5 appears 4 times, the result = 3 ). Thank you
1675653529205.png
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Try this
VBA Code:
Function NumCount(rng2 As Range)
        Dim rng As Range
        Dim dic As Object
        Set dic = CreateObject("scripting.dictionary")
        
        For Each rng In rng2
            If rng.Value <> "" Then
                If dic.Exists(rng.Value) = False Then
                    dic(rng.Value) = 0
                Else: dic(rng.Value) = dic(rng.Value) + 1
                End If
            End If
        Next rng
        
        NumCount = WorksheetFunction.Sum(dic.Items)
End Function
 
Upvote 0
How about
VBA Code:
Sub Excelpromax()
   Dim Dic As Object
   Dim Cl As Range
   Dim i As Long
   
   Set Dic = CreateObject("scripting.dictionary")
   For Each Cl In Range("B3", Range("B" & Rows.count).End(xlUp))
      If Cl.Value <> "" Then
         If Dic.Exists(Cl.Value) Then
            i = i + 1
         Else
            Dic.Add Cl.Value, Nothing
         End If
      End If
   Next Cl
   Range("F3").Value = i
End Sub
 
Upvote 0
Solution
Maybe this
Book1
BCDEF
31Result
424
53
63
74
85
95
105
115
126
Sheet1
Cell Formulas
RangeFormula
F4F4=SUM(IF(COUNTIF(B3:B12,UNIQUE(B3:B12,,FALSE))<2,0,COUNTIF(B3:B12,UNIQUE(B3:B12,,FALSE))-1))
 
Upvote 0
The OP's profile clearly shows 2010 & so does not have the Unique function.
 
Upvote 0
How about
VBA Code:
Sub Excelpromax()
   Dim Dic As Object
   Dim Cl As Range
   Dim i As Long
  
   Set Dic = CreateObject("scripting.dictionary")
   For Each Cl In Range("B3", Range("B" & Rows.count).End(xlUp))
      If Cl.Value <> "" Then
         If Dic.Exists(Cl.Value) Then
            i = i + 1
         Else
            Dic.Add Cl.Value, Nothing
         End If
      End If
   Next Cl
   Range("F3").Value = i
End Sub
Thank you
 
Upvote 0

Forum statistics

Threads
1,216,099
Messages
6,128,822
Members
449,469
Latest member
Kingwi11y

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top