I wrote a function but for some reason it doesn't work. I debugged and I still don't get what happened. I wrote some other functions to understand what doesn't work and I came to conclusion that activecell is the problematic part. For some reason when I write functions activecell. is not detected. I wrote my code below. The function is with two parameters, r (a range that is only a column, in other words something like Ai:Aj) and name (which has to be a string) and what this function is supposed to do is count the longest appearance of name continuously, in other words if I have the entered cells that have the values a,a,b,a,a,a , if name = a then the function will return 3.
Function cont(r As range, name As String) As Integer
Dim count As Integer, l As Integer
r.Cells(1).Activate
l = 0
count = 0
Do While IsEmpty(ActiveCell) = False
    If ActiveCell.Value <> name Then
        ActiveCell.Offset(1, 0).Activate
    Else
        Do While ActiveCell.Value = name
            count = count + 1
            ActiveCell.Offset(1, 0).Activate
        Loop
        If count >= l Then l = count
    End If
    count = 0
Loop
cont = l
End Function
I looked up to see if anybody else has a similar problem to what I have, but I couldn't find something useful. Maybe someone here can tell me what's wrong?Thanks!
 
     
    
