Hello!
I have a column A containing either "a"s or "b"s. In column B i want to count the number of a:s between each b. For this I'm trying to create a UDF, but I get an error:
Compile error:
Expected:expression.
I would be most grateful if anyone coulp help me with this. The UDF looks like this:
The idea is that I enter "=counter(A1)" in cell B1, and the UDF then does this:![]()
Puclic Function Counter(Rng As Range) As Integer Set counter = 0 Set Rng = Range("Rng.offset(-1,-1):Rng.Offset(-15,-1)") For Each c In Rng If Cell.Value = "a" Then counter = counter + 1 End If Next End Function
- Redefines rng to A2:A15
- Loop: checks is value in A2 "a". If it is; increase counter by 1, and check A3, A4, ..., until a value isn't "a"; then exit.
I'm very hesitant about the I use Offset to define the range, but it seems that there is a problem earlier?
Attached is a workbook showing the intended result.
Best,
Alfred
Bookmarks