Forum Discussion

DownUnderling51's avatar
DownUnderling51
Copper Contributor
Dec 21, 2018

Cumulative count formula

Is there a way to count the number of occurrences of particular randomly generated values as they are generated?

 

Specifically:

           Numbers from 1 to 10 are randomly generated in a particular cell. 

           Is there a formula to calculate the number of 1's and 2's etc that are generated cumulatively?

 

1 Reply

  • Haytham Amairah's avatar
    Haytham Amairah
    Silver Contributor

    Hi,

     

    You definitely need to a VBA code to do so!

     

    So I would suggest this one below and you will find it in the attached file.

    Sub CountTheNumberOfRandomlyGeneratedValueCumulatively()
        Dim cell As Range

        For Each cell In Range("C1:C10")
            If cell.Value = Range("A1").Value Then
                    cell.Offset(0, 1).Value = cell.Offset(0, 1).Value + 1
                    Exit For
            End If
        Next
    End Sub

     

    Hope that helps

Resources