counting the absent of a value per range

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
984
Office Version
  1. 2010
Platform
  1. Windows
VBA Code:
Sub N()
    Dim count As Integer
    count = 0
    For Each cell In Range("B2:F2")
        If cell.Value = Range("M2").Value Then
            count = count + 1
        End If
    Next cell
    If count = 0 Then
        Range("N3").Value = 1
    Else
        Range("N3").Value = 0
    End If
End Sub
Hi. This little code is just and introduction of the idea I would like to explain to you guys.
I read the range B2:F2 to see if the value on M2 is there or not, so if it is not there count one absent
after suppose I create a loop to go to the next range, but here is the trick if the next range also
do not have this value then now is " 2 times absent count"
but if the next row is present then display 0
sorry the count of two will be display on N2 and the next result "0"
will be display on O2.
I don't have at the moment xxb to display my worksheet my apology for the picture.
this this the partial array

1681682659632.png

and this is the tiny sample of the output
1681682727866.png

Thank you for your time
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
just in case if you read and still I am not clear
may be this images clear the concept
1681688785864.png

thanks.
maybe I get lucky
 
Upvote 0
second try.
VBA Code:
Sub Inte()
For i = 2 To 37
Set rngData = Range("B" & i & ":F" & i)
m = 0
  For j = 2 To 40
   n = 1
    For Each cell In rngData
     If cell = Range("M" & n) Then
      Range("N2").Offset(0, m) = n
    m = m + 1
   xit For
End If
n = n + 1
Next cell
Next j
Next i
End Sub
nothing work here
 
Upvote 0
working out
VBA Code:
Sub CountOccurrences()
    Dim i As Long, j As Long, m As Long, n As Long
    Dim bins As Range, data As Range, display As Range, cell As Range
    
    Set bins = Range("M2:M37")
    Set display = Range("N2")
    
    For i = 2 To 40
        Set data = Range("B" & i & ":F" & i)
        m = 0
        For Each cell In bins
            n = 0
            For j = 1 To data.Rows.count
                If cell.Value = data.Cells(j, 1).Value Then
                    display.Offset(m, n).Value = j
                    n = n + 1
                End If
            Next j
            m = m + 1
        Next cell
    Next i
End Sub
please give a hand here
I am no going no where
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,695
Members
449,117
Latest member
Aaagu

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